如何从笔尖单元中呈现视图
我有一个收集视图,并在Uinib上注册单元,但似乎无法在Uinib单元格内显示一个ViewController。
我想要一个ViewController,但是Nib单元格中的代码'self.present(.....)'不起作用。
如何从CEOLLECTIONVIEW NIB单元中呈现视图?
I have a collection view, and register cell with UINib, but it seems can't present a viewcontroller inside the UINib cell.
I want present a viewController, but the code inside the nib cell 'self.present(.....)' is not working.
How present a view from a ceollectionView nib cell?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
存在
是视图控制器上的一种方法,而不是视图。如果您想提供另一个视图控制器,则需要让当前视图控制器知道它。在Uikit中,这通常是通过代表模式完成的。您需要创建自己的委托协议并在视图控制器中实现。
并将委托属性添加到单元格:
集合视图数据源通常是托管收集视图的视图控制器。当您配置收集视图单元格时,您可以在这一点上设置单元格的委托:
假设您想在父视图控制器上介绍某些内容,以响应未选择的小区的特定操作。
如果您选择了单元格,则只需使用
didSelect
集合查看视图委托方法即可。如果您想添加将生活在收集视图单元格中的子视图控制器,那么您可能想重新考虑的方法略有不同(由于细胞重复使用而变得更加危险)。
present
is a method on a view controller, not a view. If you want to present another view controller, you'll need to let the current view controller know about it. In UIKit this is often done via the delegate pattern.You will need to create your own delegate protocol and implement it in the view controller.
And add a delegate property to the cell:
Collection view data sources are commonly the view controller that hosts the collection view. When you are configuring the collection view cell, you can set the delegate of the cell at this point:
This assumes you want to present something on the parent view controller in response to a particular action on the cell that is not selection.
If you're selecting the cell, then just use the
didSelect
collection view delegate method.If you want to add a child view controller that is going to live inside the collection view cell, then that's a slightly different (and more fraught with danger, because of cell reuse) approach which you may want to rethink.