【发布时间】:2018-12-30 11:31:26
【问题描述】:
我在UICollectionViewCell 内部有一个UITableView,我正在尝试从tableView(_:didSelectRowAt:) 方法内部的UITableViewCell 推送一个新视图。但是,我无法访问navigationController。我将如何导航到新视图?
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
var item = Item(name: "")
switch indexPath.section {
case 0:
item = array1![indexPath.item]
case 1:
item = array2![indexPath.item]
default:
break
}
let layout = UICollectionViewFlowLayout()
let newView = NewCollectionView(collectionViewLayout: layout)
newView.itemOfInterest = item
// Can't reference navigationController
}
【问题讨论】:
-
您可以创建将在 didSelect 中触发的委托方法,并且它应该在您可以推送的视图控制器中实现。
-
你也可以在你的ViewController中实现tableview委托的delete方法。而且您还可以选择在您的 ViewController 上调用自定义委托。
标签: ios swift uitableview uinavigationcontroller