제목이 약간 모호하다는 것을 알고 있으므로 설명하겠습니다. MainTableViewController
및 이라는 두 개의 TableViewController가 있습니다 DetailTableViewController
. 또한, 아이디어 상 계층 구조를 통해 연결된 여러 배열이 생성되었습니다.
let maincCarChoice = ["Toyota", "Nissan", "Ford"]
let toyotaCarChoice = ["Prius", "Camry", "Etios"]
let nissanCarChoice = ["Altima", "Maxima", "Rogue"]
let fordCarChoice = ["Fusion", "Focus", "Explorer"]
나는를 채울 관리가 MainTableViewController
와 mainCarChoice
배열과를 구현하는 segue
세 가지 옵션 중 하나를 터치하면로 이동하는 DetailTableViewController
. 그러나 .NET Framework DetailTableViewController
에서 사용자의 선택에 따라 각 어레이로 를 채우는 방법에 대해 확신 할 수 없습니다 MainTableViewController
. 도움을 주시면 미리 감사드립니다.
이를 달성하는 한 가지 방법은 DetailTableViewController
다음과 같이 문자열 멤버 배열을 추가하는 것입니다.
var vehiclesArray: [String]?
이 배열은 내부 테이블보기의 데이터 소스로 재생되어야합니다 DetailTableViewController
.
이제 내부 MainTableViewController
:
먼저 자동차 브랜드와 모델을 포함하는 사전을 추가하십시오.
var vehiclesDictionary = ["Toyota" : ["Prius", "Camry", "Etios"],
"Nissan" : ["Altima", "Maxima", "Rogue"],
"Ford" : ["Fusion", "Focus", "Explorer"]]
그런 다음 다음 prepare
과 같이 메서드를 재정의 합니다.
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if segue.identifier == "YourIdentifier" {
if let indexPath = self.tableView.indexPathForSelectedRow {
let selectedVehicle = vehicles[indexPath.row]
if let nextScene = segue.destination as? DetailTableViewScene {
nextScene.vehiclesArray = self.vehiclesDictionary[selectedVehicle]
}
}
}
}
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다