您好, 欢迎来到 !    登录 | 注册 | | 设为首页 | 收藏本站

在tableview内的collectionview单元格的单击上导航

在tableview内的collectionview单元格的单击上导航

在这里,您将didSelectItemAtIndexPathCategoryRow类上的委托方法上单击单元格,然后可以在其中触发委托以在ViewController 内部进行调用

    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
            let cell = tableView.dequeueReusableCell(withIdentifier: "cell") as! CategoryRow
            cell.delegate = self
            return cell
        }

    protocol CategoryRowDelegate:class {
    func cellTapped()
    }

    class CategoryRow : UITableViewCell {
         weak var delegate:CategoryRowDelegate?
        @IBOutlet weak var collectionView: UICollectionView!
    }

     func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
    if delegate!= nil {
    delegate?.cellTapped()
    }
    }

在内部添加委托函数 ViewController

func cellTapped(){
//code for navigation
}
其他 2022/1/1 18:14:16 有582人围观

撰写回答


你尚未登录,登录后可以

和开发者交流问题的细节

关注并接收问题和回答的更新提醒

参与内容的编辑和改进,让解决方法与时俱进

请先登录

推荐问题


联系我
置顶