1

in my xcode storyboard I have the standard viewController in which I have placed one Button with a Action Outlet.

I tried with an .xib which doesn't load. Further, I tried with an second ViewController in the Storyboard and a custom segue, but this also failed.

There is something I did wrong. Can anybody help me please?

  • A screenshot of storyboard with some codes, maybe? – Raptor Feb 27 '15 at 08:29
  • Storyboard: http://i61.tinypic.com/rqwxs4.png and Code: http://i58.tinypic.com/bejac6.png – Achim Rager Feb 27 '15 at 08:37
  • 1
    Why didn't you simply put the code and the screenshot in your question? Also, there are errors in your code. And you try to load a storyboard which doesn't seem to exist in the project. – Bart van Kuik Feb 27 '15 at 09:26
  • Raptor want a screenshot ;) Now, I created a new cocoa class with .xib file. In my ViewController.swift I created a function with these code: NSBundle.mainBundle().loadNibNamed("loginVC", owner: self, topLevelObjects: nil) and this function I called in the Button Action. The .xib is loading for now but backwards, form .xib to ViewController, won't work. – Achim Rager Feb 27 '15 at 09:32

2 Answers2

0

If you are using Segues, you dont need to create a ViewController and try to display it this way. Just give a (unqiue) name to your ViewController (for Example if you dont want to use a "NavigationController" you should use "Modal" as Type. You should add a ViewController Class for each ViewController in Storyboard too.

So connect ViewController1 with your second View Controller and give them a name "loginModal".

Then in your IBAction, you can use:

self.performSegueWithIdentifier("loginModal", sender: self)

That should be all. If you want to send data between ViewControllers, you should use prepareForSegue. Check out my answer here, youll find more information about sending data with segues.

Sending data with Segue with Swift

derdida
  • 14,784
  • 16
  • 90
  • 139
0

You can try like this one

Put this code inside @IBAction button.

let storyBoard : UIStoryboard = UIStoryboard(name: "Main", bundle:nil)
        let loginViewController = storyBoard.instantiateViewControllerWithIdentifier("LoginView") as loginViewController
        self.presentViewController(loginViewController, animated:true, completion:nil)

Don't forget to set identifier's name in loginViewController.

enter image description here

Nurdin
  • 23,382
  • 43
  • 130
  • 308
  • Thank you for this, but in OS X you don't have an UIStoryboard, there is nothing with UI like in iOS. Something else? – Achim Rager Mar 05 '15 at 12:06