Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

menthol moose

macrumors regular
Original poster
Jul 20, 2006
175
0
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?
 
Whether it's a void or IBAction, when I call it programmatically I call it like:

Code:
[self showInfo];
 
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?
 
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.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.