开发者

Restart drawing and events in UIViewController (iOS)

Simplified question: Is there any way to restart the navigationController of an application?. I'm trying to force the application to get his initial appearance.


Long explanation

I've a pet project in iOS and I have a weird problem with the interface that I'd like to solve. I'开发者_运维技巧d like to understand also the mechanics behind this behavior.

I've a simple welcome view, wich shows the splash screen of the application. After that, thread goes to sleep state for 1.5 seconds.

[NSThread sleepForTimeInterval: 1.5];

Then, I'm showing an advertisement view:

AdController *ad = [[AdController alloc] initWithNibName:nil bundle:nil];
[self.navigationController presentModalViewController: ad animated:YES];
[ad release];

And that's all the logic behind. After that, other controllers are pushed without incidence. I want to achieve that, if at any moment the user makes the application go to background (pushing the iPhone/iPad button) then all the controllers must disappear from the stack via pop. In order to get it I'm using applicationDidBecomeActive event from the delegate. The code is the following:

[self.navigationController dismissModalViewControllerAnimated:NO];
[self.navigationController popToRootViewControllerAnimated:YES];

This is driving to some weird visual behaviours. Depending of the moment that the user choose to push de button the transition to the first view is visible. In other cases the ad view is still present, so it is dismissed and then appears the splash screen.

It will be great if there is some way to reset this first controller (splash screen), in order to get all the transitions working as the first time. I've thought about pop it from the navigation controller and the reload another one, allocating again, but it seems a bit complicated.

Is there any simple way to achieve that?

Important Edit: If the user forces repeatedly the application to go background then these exceptions are thrown:

nested pop animation can result in corrupted navigation bar Finishing up a navigation transition in an unexpected state. Navigation Bar subview tree might get corrupted.


The easiest way that I've found is to add to the plist file a new row with key "Application does not run in background" and with value YES.

Forces the application to be completely closed and unloaded from memory when the user pushes the button.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜