Modal View Controller Issues

Discussion in 'iOS Programming' started by menthol moose, Nov 16, 2009.

  1. macrumors regular

    Joined:
    Jul 20, 2006
    #1
    I'm trying to bring up a UIImagePickerController when my application opens, but it seems that I can't present it as a Modal View Controller without calling it as part of an Interface Builder Action.

    The sample code from Apple, for example:
    Code:
    - (IBAction)showInfo {
    		FlipsideViewController *controller = [[FlipsideViewController alloc] initWithNibName:@"FlipsideView" bundle:nil];
    		controller.delegate = self;
    		
    		controller.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
    		[self presentModalViewController:controller animated:YES];
    		
    		[controller release];
    }
    This will work perfectly when I tap on a button, but when I would put that code in a void method, such as:
    Code:
    - (void)showInfo {
    		FlipsideViewController *controller = [[FlipsideViewController alloc] initWithNibName:@"FlipsideView" bundle:nil];
    		controller.delegate = self;
    		
    		controller.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
    		[self presentModalViewController:controller animated:YES];
    		
    		[controller release];
    }
    It won't display the controller and will act as if nothing happened. I've even tried calling the IBAction methods programmatically and they won't work. Is there something I'm missing? Or is the only way to present a modal view controller through an Interface Builder action called by the interface?
     
  2. Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
  3. thread starter macrumors regular

    Joined:
    Jul 20, 2006
    #3
    Whether it's a void or IBAction, when I call it programmatically I call it like:

    Code:
    [self showInfo];
     
  4. macrumors 68030

    PhoneyDeveloper

    Joined:
    Sep 2, 2008
    #4
    Hmmmm, that's cute. I never tried that before.

    If I add your single line setting the transition style to some code of mine that uses presentModalViewController it works fine.

    IB and IBAction have nothing to do with this.

    Put a breakpoint in your showInfo method and step through the code in that method. Is it called? Are you sure that controller isn't nil? This simple code should work fine.

    What do you mean by 'when my application opens?' Specifically where in your app are you calling showInfo?
     
  5. thread starter macrumors regular

    Joined:
    Jul 20, 2006
    #5
    When it doesn't work it's called in viewDidLoad in the view controller. I've stepped through the code already, and it calls it, and I've checked thoroughly. The modal view controllers that don't display are not nil, and by all accounts look exactly the same as the ones that do display. The only difference is that the ones that do display are called through Interface Builder actions.
     
  6. macrumors 68030

    PhoneyDeveloper

    Joined:
    Sep 2, 2008
    #6
    What happens if you try to call showInfo using performSelector:afterDelay:?
     
  7. Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #7
    Yeah, viewDidLoad is not where you're gonna wanna call this. Maybe try viewDidAppear.
     
  8. thread starter macrumors regular

    Joined:
    Jul 20, 2006
    #8
    Aha, that did the trick. Now it's coming up perfectly. Thank you.
     

Share This Page