Present Modal View Controller from Modal View Controller

Oct. 20, 2009

 

What I wanted to do was to present a modal view controller in the viewDidAppear method of a different modal view controller.  Specifically, I have a screen in my app that lets the user send a tweet.  I’m using the MGTwitter engine with Ben Gottleib’s Twitter+OAuth. The tweet view is presented modally.  When it appears, it checks to see if the user is authenticated, if not it automatically presents the OAuth view modally.

This was causing an “EXC_BAD_ACCESS” in:

[UIWindowController transitionViewDidComplete:fromView:toView]

After some furious debugging, I finally figured out that delaying the presentation of the OAuth view by a tenth of a second resolved the issue.  Here’s the code:

 
- (void) viewDidAppear:(BOOL)animated { 	
	[super viewDidAppear:animated];
 	if (oauthEngine) return;
 	oauthEngine = [[SA_OAuthTwitterEngine alloc] initOAuthWithDelegate:self];
 	oauthEngine.consumerKey = kOAuthConsumerKey;
 	oauthEngine.consumerSecret = kOAuthConsumerSecret;
 	[oauthEngine requestRequestToken];
 	
 	UIViewController *controller = [SA_OAuthTwitterController controllerToEnterCredentialsWithTwitterEngine:oauthEngine delegate:self]; 	
 	if (controller) {
  		[self performSelector:@selector(showTwitterOauthView:) withObject:controller afterDelay:0.1]; 	
 	} 
}  

- (void)showTwitterOauthView:(UIViewController *)controller {
     [self presentModalViewController:controller animated:YES];   
} 
 
 
 
 
 
 
 

Quick Tip: Remove Gap Between iPhone Status Bar and UINavigationBar

Feb. 2, 2009

 

If you ever come across the problem in the image below where there is a small gap between the iPhone status bar and the navigation bar, add the following code to fix it:

[viewController.view setFrame: [viewController.view bounds]];

Gap Between iPhone Status Bar and UINavigationBar