PDA

View Full Version : Modal View Controller Issues




menthol moose
Nov 16, 2009, 10:05 PM
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:

- (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:
- (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?



dejo
Nov 16, 2009, 10:30 PM
How are you calling showInfo?

menthol moose
Nov 16, 2009, 10:35 PM
Whether it's a void or IBAction, when I call it programmatically I call it like:

[self showInfo];

PhoneyDeveloper
Nov 16, 2009, 11:26 PM
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?

menthol moose
Nov 17, 2009, 12:23 AM
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.

PhoneyDeveloper
Nov 17, 2009, 08:38 AM
What happens if you try to call showInfo using performSelector:afterDelay:?

dejo
Nov 17, 2009, 10:33 AM
When it doesn't work it's called in viewDidLoad in the view controller.
Yeah, viewDidLoad is not where you're gonna wanna call this. Maybe try viewDidAppear.

menthol moose
Nov 17, 2009, 12:46 PM
Yeah, viewDidLoad is not where you're gonna wanna call this. Maybe try viewDidAppear.
Aha, that did the trick. Now it's coming up perfectly. Thank you.