我在TableView中有CollectionView。一切都好,但。當我想我的手機導航到另一個的viewController我有錯誤iOS Swift自定義單元格導航控制器
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錯誤(圖書查看,動畫:真)?行。這是錯誤的描述:
Value of 'RelatedBookTableViewCell' has no member 'navigationController'
RelatedBookTableViewCell是我的自定義單元格類:
class RelatedBookTableViewCell: UITableViewCell, UICollectionViewDataSource, UICollectionViewDelegate, UICollectionViewDelegateFlowLayout
哪裏是我的問題嗎?
謝謝。
您可以使用自定義的委託,以便UICollectionVi告訴UITableView它會告訴它的UINavigationController(通過它的UIViewController)它需要推送一個新的視圖控制器。 – Larme
單元不應該充當其他單元的數據源或委託。這是一名管理員的工作。如果你想保持這個設置,把單元格選擇委託給一個'UIViewController'實例。單元格根本沒有導航控制器屬性。 – donnywals
@Larme我在我的RelatedBookTableViewCell類中使用UINavigationControllerDelegate,但仍然存在錯誤。 – MohammadReza