Skip to content

Framework for ContainerView with multiple segues in IE in Swift

License

Notifications You must be signed in to change notification settings

brurend/ContainerManager

Repository files navigation

ContainerManager

Build Status Version Carthage compatible Platform License

Usage

ContainerViewSegueManager

ContainerViewSegueManager is responsible for telling your UIViewController which segue it should perform.

Creating your containerView

After dropping your container into your UIViewController you should name its embedSegue identifier:

Screenshots/EmbedSegueSS.png

you also need to make sure the embed UIViewController custom class is ContainerViewSegueManager

Screenshots/ContainerViewSegueManagerSS.png

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
}

EmptySegue

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:

Screenshots/EmptySegueSS.png

ContainerDataManager

ContainerDataManager is responsible for deciding which segueIdentifier should be passed to performSegueWithIdentifier:sender: of ContainerViewSegueManager based on your application data and needs.

Subclassing ContainerDataManager

You should create a subclass of ContainerDataManager and override the additionalSetup method:

MyContainerDataManager.h

import UIKit
import ContainerManager

class MyContainerData: ContainerDataManager

Choosing which segueIdentifier will be used

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"
    }
}

Swapping viewController

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)

Requirements

ContainerManager supports iOS 8.3+. Updated to Swift 3.0

Installation

ContainerManager supports multiple methods for installing the library in a project.

Installation with CocoaPods

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

Installation with Carthage

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.

Author

Bruno Rendeiro, brurend@hotmail.com.

License

ContainerManager is available under the MIT license. See the License file for more info.

About

Framework for ContainerView with multiple segues in IE in Swift

Resources

License

Stars

Watchers

Forks

Packages

No packages published