Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

work with existing viewcontrollers in storyboard? #5

Closed
Jackson0111 opened this issue Dec 21, 2015 · 14 comments
Closed

work with existing viewcontrollers in storyboard? #5

Jackson0111 opened this issue Dec 21, 2015 · 14 comments

Comments

@Jackson0111
Copy link

Is there a way to integrate EZSwipeController with existing view controllers in storyboard? I tried to do this but received an error when EZSwipeController tried to access view controllers. error : fatal error: unexpectedly found nil while unwrapping an Optional value

@Esqarrouth
Copy link
Owner

Can you show me which line it was at?

@Jackson0111
Copy link
Author

It was at the very first few lines of my first view controller. captionTextField.delegate = self

@Esqarrouth
Copy link
Owner

I don't know what a captionTextField is. I need more info, this doesn't seem to be related to EZSwipeController

@Jackson0111
Copy link
Author

Everything in EZSwipeController seems to work fine, but the error was thrown when it tried to access my existing view controllers. captionTextField is a UITextField in one of my existing view controllers, as soon as I comment all IBoutlets everything works fine. I was just wondering if there was a way to integrate existing view controllers in storyboard with EZSwipeController. In the demo project, it looks like everything was added programmatically, but can i use storyboard tho?

@Esqarrouth
Copy link
Owner

Are you trying to create this inside a small textfield? You can't use storyboard without making some edits but you can call from a button that is inside the storyboard

@Esqarrouth
Copy link
Owner

Hello, have you been able to solve this problem?

@Jackson0111
Copy link
Author

No, I just used a UIPageViewController instead

@Esqarrouth
Copy link
Owner

😢
If there is a way to solve the problem you had, let me know or send a pull request please

@Jackson0111
Copy link
Author

I will try!

On Jan 23, 2016, at 10:59 PM, Goktug Yilmaz <notifications@github.commailto:notifications@github.com> wrote:

[:cry:]
If there is a way to solve the problem you had, let me know or send a pull request please


Reply to this email directly or view it on GitHubhttps://github.com//issues/5#issuecomment-174245106.

@Esqarrouth
Copy link
Owner

http://stackoverflow.com/questions/tagged/ezswipecontroller

You can ask your question here if you want to. If you solved the problem please send a pull request. Thanks!

@blazierkyle
Copy link

I had run into this issue as well. I believe it is because Jackson and I both have previously made ViewControllers in a Storyboard file, and are now trying to use them in the EZSwipeController. However, if you have objects that were outletted to the ViewController class, since it hasn't been instantiated from the storyboard, it is nil and therefore causes a crash.

To fix this, in my custom subclass of EZSwipeController's setupView() function, I instantiate the three ViewController's I need from the storyboard (using storyboard.instantiateViewControllerWithIdentifier), save it to my custom subclass of the EZSwipeController and then reference that array of ViewControllers in the viewControllerData() extension func.

@otymartin
Copy link

otymartin commented Sep 19, 2016

@blazierkyle @goktugyil can you provide code example? I did that and still get nil

import UIKit
import EZSwipeController

class MainViewController: EZSwipeController {

    var swipeArray: [UIViewController]!

    override func setupView() {
        datasource = self
        let storyboard = UIStoryboard(name: "Main", bundle: nil)
        let stream = storyboard.instantiateViewControllerWithIdentifier("Stream") as! StreamViewController
        let camera = storyboard.instantiateViewControllerWithIdentifier("Camera") as! CameraViewController
        self.swipeArray = [stream, camera]
    }
    override func viewDidLoad() {
        super.viewDidLoad()
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }

}

extension MainViewController: EZSwipeControllerDataSource {
    func viewControllerData() -> [UIViewController] {
        return self.swipeArray
    }

    func indexOfStartingPage() -> Int {
        return 0
    }
}


//**UPDATE**: In app delegate, I had the wrong viewController in window!.rootViewController. It works now!.
window = UIWindow(frame: UIScreen.mainScreen().bounds)
        window!.rootViewController = MainViewController()
        window!.makeKeyAndVisible()

@blazierkyle
Copy link

@otymartin Happy to hear you got it working!

@otymartin
Copy link

otymartin commented Sep 19, 2016

@blazierkyle Thanks for the solution, i was so happy to finally get it to work. Im curious though if you ever managed to get rid of bounces in first & last VC. Thats what im struggling with now in #38

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants