I have a UINavigationController and on the UINavigationBar i have a Button. When i press this Button, a new UINavigationController is presented modally as a UIModalPresentationFormSheet. This works.
But i recognized that the presentation of the FormSheet is quite time consuming. I put two logs in the action method (“start” and “finish”, see code below), one in the first and one in the last line. The log time tells me, that it takes about 1,5 to 2 seconds to run this code.
Thats the Action method called from the UINavigationItem:
- (IBAction)addBtnPressed:(id)sender{
NSLog(@"start");
FooViewController *fooContr = [[FooViewController alloc] init];
fooContr.delegate = self;
UINavigationController *navContr = [[UINavigationController alloc] initWithRootViewController:fooContr];
[fooContr release];
navContr.modalPresentationStyle = UIModalPresentationFormSheet;
[self.navigationController presentModalViewController:navContr animated:YES];
[navContr release];
NSLog(@"finish");
}
It seems that the line
[self.navigationController presentModalViewController:navContr animated:YES];
takes 90% of the time.
Does anybody know whats going on here and how to optimize that?
Preload the
UINavigationControllerwith theFooViewControllerso when you present it it is already in memory.What it is probably taking so much time is the loading of the
FooViewControllerinstance’s view.You can make it load by doing something to it. Like
UIView *view = fooContr.view;You should do this before the button that presents the modal view controller gets clicked. Otherwise it will probably have the same effect.