3

In my storyboard I have a NavViewController which sets the root view to ViewController1. ViewController1 then has a push segue to ViewController2 with the Identifier "socialSeg". ViewController1 has a UIImageView which I use to load the camcorder. After the user records the video and selects 'Use' i want to load the next view controller. In ViewController1.m I have the following:

- (void)imagePickerController:(UIImagePickerController *)picker
didFinishPickingMediaWithInfo:(NSDictionary *)info 
{
    NSLog(@"Performing Segue with ID");
    [self performSegueWithIdentifier:@"socialSeg" sender:self];
}

-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    NSLog(@"Prepping");
}

Both NSLogs run, but nothing happens on my screen. I don't see the ViewController2, and no error messages pop up. Am I doing this correct?

Related question: Should I be running performSegueWithIdentifier on self (the current ViewController), or should they be ran on self.navigationController?

Edit: I tried to shorten my question somewhat to keep the post shorter, I realized you might need more context.

Here is my full storyboard. Basically "Video View Controller" would be ViewController1 and "Social View Controller" would be ViewController2. When I click on the "Root View Controller" button (Record Video), that segue works fine, which is why I left it out. Is there any chance the "Root View Controller" could be throwing things off?

Shaik Riyaz
  • 11,204
  • 7
  • 53
  • 70
Dan Ramos
  • 1,092
  • 2
  • 19
  • 35
  • Are you sure that the segue is correctly wired and named? Try, if it works when you init it via UI event, e.g. pushing a button. – Matthias Sep 19 '13 at 04:02
  • I edited my question to include a screen shot of my storyboard. I'm 99% sure everything is hooked up and named properly (still new to ios dev). I tried wiring up a button to the ViewController2 instead of the running it from `didFinishPickingMediaWithInfo` and that worked fine. – Dan Ramos Sep 19 '13 at 04:17

1 Answers1

3

There is nothing wrong with your performSegue code. It seems like your picker animation is still being run when you perform this Segue. Try calling performSegue in the completion block of presentViewController by modifying your present call as given below.

[imagePickerController presentViewController:YES completion:^() {
    NSLog(@"Performing Segue with ID");
    [self performSegueWithIdentifier:@"socialSeg" sender:self];
}];

Please make sure to replace imagePickerController with the name of your popup image picker controller.

Its not ideal solution but you can also delay execute your your performSegue to make sure your image picker animation has stopped as:

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
   //1.5 is number of seconds its going to wait before executing the block of code
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 1.5 * NSEC_PER_SEC), dispatch_get_current_queue(), ^{
        NSLog(@"Performing Segue with ID");
        [self performSegueWithIdentifier:@"socialSeg" sender:self];
    });
}

NOTE: The issue is that image picker popup animation is still in progress (to close the picker after user has picked an image or video) when performSegue tries to start another animation to load next view controller. Since one animation has not finished yet therefore performSegue animation gets ignored and view controller does not load.

Here is a related question and answer: performSegueWithIdentifier not working

Community
  • 1
  • 1
Yas Tabasam
  • 10,517
  • 9
  • 48
  • 53
  • I tried that but it said `dismissModalViewControllerAnimated` is depreciated in ios6. I replaced it with `dismissViewControllerAnimated` (assuming this is equivalent ? ) and still didn't have any luck – Dan Ramos Sep 19 '13 at 04:13
  • I updated the answer. Please dont forget to replace `imagePicker` variable with the name of your image picker controller. – Yas Tabasam Sep 19 '13 at 04:22
  • Ok i tried that and now I get `Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Application tried to present modally an active controller .` – Dan Ramos Sep 19 '13 at 04:31
  • Are you trying to dismiss it in VideoViewController or ViewController1? – Yas Tabasam Sep 19 '13 at 04:39
  • VideoViewController is actually the same as ViewController1 (sorry my original post was not that clear). This is the ViewController that I'm currently on and want to segue off of. – Dan Ramos Sep 19 '13 at 04:41
  • Holly sh*t its magic! I've been after this for 2 days and it finally works. I'm just confused now, aren't we technically loading/adding two ViewControllers to the stack now? It seems like we are loading the UIImagePickerController along with the Social View/ViewController2 at the same time via `performSegueWithIdentifier:@"socialSeg"`? – Dan Ramos Sep 19 '13 at 05:17
  • Glad it worked. The issue had nothing to do with the number of view controllers, instead your image picker popup animation was still in progress (to close the picker after you picked an image or video) when you were trying to start another animation to load social view controller. Since one animation has not finished yet therefore your performSegue animation was getting ignored. – Yas Tabasam Sep 19 '13 at 05:23