1

I have been recently started learning iOS programming using Swift language. I managed to somehow put the elements on the page and interact with them. Now, in my sample application, I have a login screen, when user enters username and password, I send the details to my web service and get status success or failed.

I managed to show an alert when authentication fails. When success, how do I navigate to home scene or replace the current login scene programmatically. I have researched over the internet and found no solution. Please help

EDIT: I am using story boards on xcode6 beta

Raghavendra
  • 5,281
  • 4
  • 36
  • 51
  • See here: http://stackoverflow.com/questions/24038215/how-to-navigate-from-one-view-controller-to-another-using-swift – Widerberg Aug 07 '14 at 13:37
  • 3
    Are you using Storyboards, XIB files, or are you talking about SpriteKit scenes? – Kamaros Aug 07 '14 at 13:39
  • @Kamaros, I am using storyboards – Raghavendra Aug 08 '14 at 06:08
  • @AlexanderW, That answer was not helpful to me, I am not using UINavigationController, I just want to replace the current login screen with home screen when successful login. Please help – Raghavendra Aug 08 '14 at 06:31
  • I am a beginner and learning iOS programming in swift. Please tell me reason why i got downvotes, I am now banned from asking questios. – Raghavendra Aug 08 '14 at 08:25

2 Answers2

1

Take a look at the documentation on segues, here. In a nutshell, create a segue with a unique identifier between two view controllers in your storyboard. Then to execute the segue and move from the first view controller to the second, call [performSegueWithIdentifier:sender:], passing the identifier you assigned to the segue as the first parameter.

If you wish to pass any data between your view controllers, you can do this by overriding [prepareForSegue:sender:], accessing the source and destination view controllers via the segue parameter, and differentiating between multiple segues using the sender parameter and segue's identifier property.

Kamaros
  • 4,536
  • 1
  • 24
  • 39
0

Take a button, add action to it and add the below code. The destination view is UllasViewController, replace UllasViewController with the name as you need in program. Give the name in the storyboard identity for the view controller and paste the below code in your button action

@IBAction func btnRegister(sender: AnyObject) {
    let controller : UllasViewController = self.storyboard?.instantiateViewControllerWithIdentifier("UllasViewController") as! UllasViewController
    self.navigationController?.pushViewController(controller, animated: true)
}
egor.zhdan
  • 4,555
  • 6
  • 39
  • 53
Ullas Pujary
  • 349
  • 4
  • 14