ios - UIcollectionview Custom Cell class to doselectitem at

标签 ios swift uicollectionview

我的 Collection View 包含多个以编程方式创建的自定义单元格类。有趣的部分是我将有一个包含另一个 collectionview 的单元格。那么如何点击进入这个collectionview来呈现一个新的view controller呢?下面是关于如何创建单元格的示例代码。

class MainView: UIViewController {
** main view to display UIcollectionview **
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: userCellIdent, for: indexPath) as! UserContainerViewCell
            cell.Users = users * to display users array*
            return cell

}


class UserContainerViewCell: UICollectionViewCell{
* the uicollectionview that inside a cell , also contains extension to UIcollectioview datasource and delegate to display the cells within this cell*

  func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
        let cell = collectionView.dequeueReusableCell(withReuseIdentifier: ident, for: indexPath) as! userCell
        let user = featureUsers![indexPath.row]
        cell.config(withUser: user)

        return cell
    }
}



class userCell: UICollectionViewCell {

func config(withUser: UserProfile) { }
** cell class to display the info from the user array **
}

那么对于这个设置,如何点击单元格并在数组中呈现一个带有用户信息的新 Controller ?

最佳答案

您必须在内部 collectionViewCell 的 didSelect 上将委托(delegate)或命中通知传递给 viewController,并且在该方法中您可以呈现新的 View Controller 。

查看链接

Swift: How to use "didSelectItemAtIndexPath" in UITableViewController(contains UICollectionView)?

关于ios - UIcollectionview Custom Cell class to doselectitem at,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50315012/

相关文章:

iphone - 当我在后台运行 NSURLConnection 错误时......我该如何修复?

ios - CAShapeLayer 上的 CABasicAnimation 不适用于路径更改

swift - 在 Firebase 中查询以下 AutoID

ios - 将图像数组转换为视频时出现问题

swift - 将容器 View 的内容保留在导航堆栈中

ios - UICollectionView 始终自动调整单元格大小。不使用从委托(delegate)返回的尺寸

ios - AppDelegate 的用途是什么,我如何知道何时使用它?

ios - XCode 4-libsqlite3.dylib:没有这样的文件或目录

swift - 使用 Firestore 删除帐户和文档时出现问题

ios - UIcollectionview 未获取调用数据源