【发布时间】:2018-06-09 16:37:27
【问题描述】:
我四处搜寻,并没有真正找到发生这种情况的原因。基本上,我按照 Jared Davison 的本教程 https://www.youtube.com/watch?v=yupIw9FXUso 创建表视图单元到多个视图控制器。在他的示例中,一切正常,但由于某种原因,当您单击我的代码中的表格视图单元格时,该单元格以灰色突出显示。然后,当用户单击单独的表格视图单元格时,将加载应该由第一个表格视图单元格加载的视图控制器。如果用户随后点击原始表格视图单元格,则加载本应由第二个表格视图单元格加载的页面。总而言之,所有的视图控制器都是在“点击”后加载的。
这是表格视图的代码:
//Feed Navigation Functions
public func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return elements.count
}
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
return 75
}
public func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "feedCell") as! FeedTableViewCell
cell.txtTitle.text = "The Fight Against \(elements[indexPath.row])"
cell.issueIcon.image = UIImage(named: "Issue Icons_\(elements[indexPath.row])")
return cell
}
func tableView(_ tableView: UITableView, didDeselectRowAt indexPath: IndexPath) {
let vcName = identities[indexPath.row]
let viewController = storyboard?.instantiateViewController(withIdentifier: vcName)
self.navigationController?.pushViewController(viewController!, animated: true)
}
更新:该数组是一个简单的字符串数组,例如 [One, Two, Three] 数组中有 6 个字符串。
【问题讨论】:
标签: ios swift uitableview segue pushviewcontroller