2016-12-12 1 views
1

전 새로운 iOS 프로그래머입니다. Swift3으로 첫 번째 시도해보세요. 이것은 다른 Zones Area 데이터 공유 기능과 같습니다. 소원이 도움이 될 수있는 문제가 있습니다. 깊이 감사드립니다.스위프트 3 동일한 초에 다른 배열을 표시하는 방법 컨트롤러 셀보기

두 개의 ViewController이 있고 각보기에는 하나의 셀이 있습니다. 뷰에서 B 세포

함께 휴대 B ViewControllerViewController에게 I는 Array 예컨대 가지고

var USA = [String]() 

USA = ["NY", "NJ", "CF", "LA", "WD"] 

그리고

NY = ["zone one", "zone two", "zone three", "zone 4", "zone 5"] 
NJ = ["eastZone", "southZone", "northZone", "westZone"] 
CF = ["midtown", "downtown", "uptown", "county"] 
LA = ["firstZone", "SndZone", "ThreeZone", "fourZone", "fiveZone"] 
WD = ["eastPart", "westPart", "downPart", "upPart", "countyPart"] 

경우하므로보기에서 I는 표시 할 셀 :

override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { 
    return USA.count 
} 

총이 5 행

다음 i는 LA의 B보기를 선택한 후 나는

["firstZone", "SndZone", "ThreeZone", "fourZone", "fiveZone"] in B View cell, if I selected A View's row "LA" 

을 보여줄 수있는 방법을 질문 당신이

override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) 

을 원하는 행을 선택하려면이 FUNC를 사용 5 행을 표시 할 수 있습니다.

["firstZone", "SndZone", "ThreeZone", "fourZone", "fiveZone"] 

NY를 선택한 경우 NY의 내가보기에 필요한 B보기의 데이터 ry ~

다른 행을 선택했을 때 다른 셀 데이터를 표시하고 싶습니다. ViewController은 스마트 한 방법으로 가능합니까 ?? 또는 ViewController 또는 클래스가 더 필요합니까? 도와주세요 !! 고마워요 ~

+0

하나의 화면으로 표시하고 싶습니까? –

+0

"보기 컨트롤러의 도시"에서 다른 데이터 (영역)가있는 단일 화면 "B보기 컨트롤러의 셀"에 표시하려는 경우 –

답변

0

각 개체에 하위 배열이 들어있는 개체 배열로 데이터를 설정하십시오. 를 A 컨트롤러

예컨대 :

class Location { 
    var name: String 
    var sections: [String] 

    init(_ key: String, sections: [String]) { 
     name = key 
     self.sections = sections 
    } 
} 

let USA = [Location("NY", sections: ["zone one", "zone two", "zone three", "zone 4", "zone 5"]), 
     Location("NJ", sections: ["eastZone", "southZone", "northZone", "westZone"]), 
     Location("CF", sections: ["midtown", "downtown", "uptown", "county"]), 
     Location("LA", sections: ["firstZone", "SndZone", "ThreeZone", "fourZone", "fiveZone"]), 
     Location("WD", sections: ["eastPart", "westPart", "downPart", "upPart", "countyPart"])] 

는 셀 IndexPath.row에있는 객체에 대한 Location.name 보여줍니다. B 컨트롤러의 경우 선택한 Location 개체를 전달하고 셀에 대해 Location.sections 개수와 항목을 사용합니다.

+0

도움을 주셔서 감사합니다. –