【发布时间】:2020-10-08 06:15:12
【问题描述】:
是否可以将来自搜索栏呈现视图控制器的数据添加到区域视图控制器。
当我点击搜索栏时,会出现一个当前视图控制器,然后我选择所需的单元格,它会消失并且数据从当前视图控制器传递到区域视图控制器。
这里是搜索栏显示视图控制器
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
let cell = tableView.dequeueReusableCell(withIdentifier: "Cell") as! CellForShowAllTVC
print("Did Select call ***********")
let storyboard = UIStoryboard(name: "Rider", bundle: nil)
let vc = storyboard.instantiateViewController(withIdentifier: "yourzoneVC") as! YourZoneVC
vc.arryOfCityName.append(arryOfCity[indexPath.row]) //Pass array to zone View Controller but its not worked
self.dismiss(animated: true, completion: nil)
}
这里是区域视图控制器
override func viewDidAppear(_ animated: Bool) {
print(arryOfCityName)
yourZonTV.reloadData()
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return arryOfCityName.count
}
//But its show data coming from search bar
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
let storyboard = UIStoryboard(name: "Rider", bundle: nil)
Cell3ForYourZone
let vc = storyboard.instantiateViewController(withIdentifier: "zoneinmapviewVC") as! ZoneInMapViewVC
vc.getCityCompare1 = arryOfCityName[indexPath.row] as? String
navigationController?.pushViewController(vc, animated: true)
}
【问题讨论】:
-
第一个 sn-p 完全没有意义。
let cell = ...毫无意义,vc被实例化然后被丢弃。
标签: ios swift uitableview uisearchbar