Ios 单击表视图单元格内的uicollectionview单元格时继续
我有以下情况: ExploreViewController是一个具有CategoryTableViewCell(UITableViewCell的子类)的表视图控制器 CategoryTableViewCell具有带有UICollectionViewCells的CollectionView 当用户单击UICollectionViewCell时,我希望基于UICollectionViewCell数据将ExploreViewController分为BookListViewController。每个UICollectionViewCell代表一个单独的类别 如何使用swift进行此操作?我尝试使用委托协议,但当我在ExploreViewController内的委托函数内调用performsgue时,我得到一个错误 在CategoryTableViewCell中Ios 单击表视图单元格内的uicollectionview单元格时继续,ios,swift,uitableview,uicollectionview,delegates,Ios,Swift,Uitableview,Uicollectionview,Delegates,我有以下情况: ExploreViewController是一个具有CategoryTableViewCell(UITableViewCell的子类)的表视图控制器 CategoryTableViewCell具有带有UICollectionViewCells的CollectionView 当用户单击UICollectionViewCell时,我希望基于UICollectionViewCell数据将ExploreViewController分为BookListViewController。每个UI
func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
print("test12")
self.delegate?.didSelectInEmbeddedCollection()
}
}
protocol CategoryTableViewCellDelegate {
func didSelectInEmbeddedCollection()
}
在ExploreView控制器中
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
print("test14")
if segue.identifier == "toBookListFeatured",
let destination = segue.destination as? BookListViewController,
let selectedIndexPath = self.tableViewFeaturedCats.indexPathForSelectedRow,
let selectedCell = self.self.tableViewFeaturedCats.cellForRow(at: selectedIndexPath) as? CategoryTableViewCell
{
let collectionView = selectedCell.collectionView
let indexPathC = collectionView?.indexPathsForSelectedItems?.first
let cell = collectionView?.cellForItem(at: indexPathC!) as? CategoryCollectionViewCell
destination.data = cell!.label.text
} else {
// Get the new view controller using segue.destinationViewController.
// Pass the selected object to the new view controller.
let dc = segue.destination as! BookListViewController
dc.data = self.tableRowData["name"] as! String;
dc.searchByCategory = true
}
}
}
extension ExploreViewController: CategoryTableViewCellDelegate {
func didSelectInEmbeddedCollection() {
performSegue(withIdentifier: "toBookListFeatured", sender: nil)
}
}
什么错误?哪个错误?你的代码块在哪里?我添加了代码。如上所述,请添加您的错误行。我没有收到错误行,只是sigartsigart表示无法访问零或不存在的内容,
BookListViewController
是否在ObjC中?