【发布时间】:2016-08-24 08:01:58
【问题描述】:
我在 TableView 中有 CollectionView。一切都好但是。当我想将我的单元格导航到另一个 viewController 时出现错误
func collectionView(collectionView: UICollectionView, didSelectItemAtIndexPath indexPath: NSIndexPath){
let storyboard = UIStoryboard(name: "Main", bundle: NSBundle.mainBundle())
let bookView: BookSingleController = storyboard.instantiateViewControllerWithIdentifier("BookSingle") as! BookSingleController
self.navigationController?.pushViewController(bookView, animated: true)
bookView.bookID = "\(self.books[indexPath.row].id)"
print(self.books[indexPath.row].id)
}
Xcode 在 self.navigationController?.pushViewController(bookView, animated: true) 行上显示错误。这是错误描述:
Value of 'RelatedBookTableViewCell' has no member 'navigationController'
RelatedBookTableViewCell 是我的自定义单元格类:
class RelatedBookTableViewCell: UITableViewCell, UICollectionViewDataSource, UICollectionViewDelegate, UICollectionViewDelegateFlowLayout
我的问题在哪里?
谢谢。
【问题讨论】:
-
您可以使用自定义委托,以便 UICollectionView 告诉 UITableView,后者将告诉其 UINavigationController(通过它是 UIViewController)它需要推送一个新的视图控制器。
-
一个单元格不应充当数据源或代表其他单元格。这是控制器的工作。如果您确实想保留此设置,请将单元格选择委托给
UIViewController实例。单元格根本没有导航控制器属性。 -
@Larme 我在我的 RelatedBookTableViewCell 类中使用 UINavigationControllerDelegate 但错误仍然存在。
标签: ios objective-c swift uitableview uicollectionviewcell