测试已测试 | ✗ |
语言语言 | SwiftSwift |
许可证 | MIT |
发布上次发布 | 2016 年 2 月 |
SPM支持 SPM | ✗ |
由 Francisco Gonçalves 维护。
轻松将任何 ViewController 嵌入 CollectionView/TableView Cell。
为了利用这个库,您需要遵循以下步骤
首先创建一个继承自 ViewControllerCollectionCell 的 cell,并用要展示的 ViewController 参数化它。
class MyCollectionCell: ViewControllerCollectionCell<ViewController> {
override func instantiateViewController() -> ViewController? {
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let vc = storyboard.instantiateViewControllerWithIdentifier("ViewC") as! ViewController
return vc
}
}
然后注册您的 cell。
override func viewDidLoad() {
super.viewDidLoad()
// Register cell classes
self.collectionView!.registerClass(MyCollectionCell.self, forCellWithReuseIdentifier: reuseIdentifier)
}
并将当前视图控制器设置为父视图控制器。
override func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCellWithReuseIdentifier(reuseIdentifier, forIndexPath: indexPath)
if let cell = cell as? MyCollectionCell {
cell.parentViewController = self
cell.viewController?.model = model[indexPath.item]
}
return cell
}
由于此库的主要用途是与 UICollectionViewControllers 或 UITableViewControllers 一起使用,因此它提供了一些基类,例如 ViewControllerCollectionCell
和 ViewControllerTableCell
。但您可以通过使所需视图实现 BindableView
协议来将其绑定到任何视图控制器。
要运行示例项目,请克隆仓库,并首先从 Example 目录运行 pod install
。
通过 CocoaPods 可以安装 BindViewControllerToView。要安装它,只需将以下行添加到您的 Podfile 中
pod "BindViewControllerToView"
Francisco Gonçalves, @franciscocsg
在 MIT 许可证下提供 BindViewControllerToView。有关更多信息,请参阅 LICENSE 文件。