Latest 0.2.2
Homepage https://github.com/franciscocgoncalves/BindViewControllerToView
License MIT
Platforms ios 8.0, requires ARC
Authors

Version
License
Platform

Easily embed any ViewController in a Collection/Table View Cell.

Basic Usage

To take advantage of this library there are a few steps that you need to follow:

CollectionViewCell

Start by creating a cell that extends from ViewControllerCollectionCell and parameterize it with the ViewController that you intend to present.

class MyCollectionCell: ViewControllerCollectionCell<ViewController> {
  override func instantiateViewController() -> ViewController? {
    let storyboard = UIStoryboard(name: "Main", bundle: nil)
    let vc = storyboard.instantiateViewControllerWithIdentifier("ViewC") as! ViewController
    return vc
  }
}

CollectionViewController

Then register your cell.

override func viewDidLoad() {
    super.viewDidLoad()

    // Register cell classes
    self.collectionView!.registerClass(MyCollectionCell.self, forCellWithReuseIdentifier: reuseIdentifier)
}

And set the current view controller as parent view controller.

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
}

Customization

As the main purpose of this library is to be used with UICollectionViewControllers or UITableViewControllers it provides already some base classes like ViewControllerCollectionCell and ViewControllerTableCell. But it can be used to bind any view to any view controller by making the desired view implement the BindableView protocol.

Example

To run the example project, clone the repo, and run pod install from the Example directory first.

Installation

BindViewControllerToView is available through CocoaPods. To install
it, simply add the following line to your Podfile:

pod "BindViewControllerToView"

Author

Francisco Gonçalves, @franciscocsg

License

BindViewControllerToView is available under the MIT license. See the LICENSE file for more info.

Latest podspec

{
    "name": "BindViewControllerToView",
    "version": "0.2.2",
    "summary": "Easily embed any ViewController in a Collection/Table View Cell.",
    "description": ""This library allows you to embed any ViewController in any view."n"Its main purpose is to allow embeding View Controllers in Cells by providing Collection/TableViewCell base classes that you can extend."",
    "homepage": "https://github.com/franciscocgoncalves/BindViewControllerToView",
    "license": "MIT",
    "authors": {
        "Francisco Goncu0327alves": "[email protected]"
    },
    "source": {
        "git": "https://github.com/franciscocgoncalves/BindViewControllerToView.git",
        "tag": "0.2.2"
    },
    "social_media_url": "https://twitter.com/franciscocsg",
    "platforms": {
        "ios": "8.0"
    },
    "requires_arc": true,
    "source_files": "Pod/Classes/**/*",
    "resource_bundles": {
        "BindViewControllerToView": [
            "Pod/Assets/*.png"
        ]
    },
    "libraries": "xml2",
    "xcconfig": {
        "HEADER_SEARCH_PATHS": "$(SDKROOT)/usr/include/libxml2"
    }
}

Pin It on Pinterest

Share This