ContainerViewSegueManager
is responsible for telling your UIViewController
which segue it should perform.
After dropping your container into your UIViewController
you should name its embedSegue identifier:
you also need to make sure the embed UIViewController
custom class is ContainerViewSegueManager
and then in your UIViewController
class override prepareForSegue:sender:
with references to ContainerViewSegueManager
and
an instance of your ContainerDataManager
subclass:
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
if segue.identifier == "embedSegue" {
self.containerView = segue.destinationViewController as! ContainerViewSegueManager
let data = MyContainerData(fromParent: self, fromContainer: self.containerView)
self.containerView.containerDataClass = data
}
}
Make sure shouldPerformSegueWithIdentifier:sender:
returns YES
override func shouldPerformSegueWithIdentifier(identifier: String, sender: AnyObject?) -> Bool {
return true
}
All segues from your ContainerViewSegueManager
to your UIViewController
should be of the type EmptySegue
and have an identifier, don't forget to set the "Module" to ContainerManager
:
ContainerDataManager
is responsible for deciding which segueIdentifier
should be passed to performSegueWithIdentifier:sender:
of ContainerViewSegueManager
based on your application data and needs.
You should create a subclass of ContainerDataManager
and override the additionalSetup
method:
MyContainerDataManager.h
import UIKit
import ContainerManager
class MyContainerData: ContainerDataManager
ContainerDataManager additionalSetup
method will be overridden by your class implementation. self.currentSegueIdentifier
must NOT be nil.
override func additionalSetup() {
let array = [1,2,3]
if array.count != 0 {
self.currentSegueIdentifier = "FirstViewController"
}
else {
self.currentSegueIdentifier = "SecondViewController"
}
}
You can use ContainerViewSegueManager swapFromViewController:toViewController
to go from one UIViewController
to another UIViewController
easily.
let storyboard = UIStoryboard.init(name: "Main", bundle: nil)
let second = storyboard.instantiateViewControllerWithIdentifier("SecondViewController")
container.swapFromViewController(self, toViewController: second)
ContainerManager supports iOS 8.3+. Updated to Swift 3.0
ContainerManager supports multiple methods for installing the library in a project.
ContainerManager is available through CocoaPods. To install
it, simply add the following line to your Podfile
:
source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '8.3'
pod 'ContainerManager', '~> 2.0.0'
Then, run the following command:
$ pod install
Carthage is a decentralized dependency manager that builds your dependencies and provides you with binary frameworks.
You can install Carthage with Homebrew using the following command:
$ brew update
$ brew install carthage
To integrate ContainerManager into your Xcode project using Carthage, specify it in your Cartfile
:
github "brurend/ContainerManager" ~> 2.0.0
Run carthage
to build the framework and drag the built ContainerManager.framework
into your Xcode project.
Bruno Rendeiro, brurend@hotmail.com.
ContainerManager is available under the MIT license. See the License file for more info.