1

I am new to iOS. I have a very similar requirement like my working Android project. The requirement is that in my LoginActivity onCreate(), I am checking for some condition and if it is true then I am launching my next Activity using an Intent.

I am trying to perform the same functionality form my iOS app. In my LoginViewController viewDidLoad(), after checking for some condition, I am calling [self performSegueWithIdentifier:@"myNextControllerSegue" sender:nil];.

But, my ViewController is not changing to next view controller. Any help would be appreciated.

Hello World
  • 239
  • 6
  • 17
  • call you segue in main thread or move to viewdidappear or viewwillappear – Anbu.Karthik Jul 03 '17 at 14:04
  • 1
    make sure you configured the segue in `Storyboard` with the same name `myNextControllerSegue`. – Hamdullah shah Jul 03 '17 at 14:08
  • @Anbu.Karthik it didn't work if I call it in viewWillAppear(). When I move the logic to viewDidAppear() then it is working but I am seeing a flickering where I can see my login UI too. How to avoid that flicker? – Hello World Jul 03 '17 at 14:11
  • https://stackoverflow.com/a/41887007/5461400 – Harshal Valanda Jul 03 '17 at 15:03
  • If you find out partway through the presentation of a view controller that you don't want to present it, then you found out too late. Do the logic that checks your login condition before you committing to a VC, then create the one you need. – danh Jul 03 '17 at 15:39

3 Answers3

1

viewDidLoad: is not used for segue performing. You should call the segue in viewDidAppear:, where the view structure is already established.

Tamás Sengel
  • 55,884
  • 29
  • 169
  • 223
1

Need to perform segue at right place.you are tried to loading another view before first one in hierarchy.So viewDidAppear is called you have a fully loaded view to modify.

   - (void)viewDidAppear:(BOOL)animated
    {
        [super viewDidAppear:animated];
        [self performSegueWithIdentifier:@"myNextControllerSegue" sender:nil];
    }

To remove that flickering, just hide the view in your viewWillApear method.

otherwise as quick search you can do that into main thread also like below

dispatch_async(dispatch_get_main_queue(), { () -> Void in   
  //perform segue
})
Dharma
  • 3,007
  • 3
  • 23
  • 38
0

On your Storyboard, click on your view controller, go to the "Connections inspector" part, and in "Triggered segues", drag the "+" button to the controller you want to reach.

Now click on your segue and go on "Attributes inspector" part, and set "myNextControllerSegue" for identifier.

Valentin Garcia
  • 143
  • 1
  • 2
  • 10