我有一个视图控制器(视图 A)在用户按下按钮时呈现模式视图(B),而视图 B 本身有一个按钮来呈现视图 C。我的问题是,如果用户在视图 B 或显示 C,下次启动应用程序时将出现相同的视图。有没有办法在退出时关闭视图 B 和 C 或在应用程序启动时显示视图 A?谢谢你的帮助
问问题
2380 次
1 回答
6
我假设你的意思是当应用程序进入后台时。
在您的应用程序委托中,您可以通过 applicationDidEnterBackground: 方法关闭您的控制器。
最好的方法可能是在您的视图控制器类中添加一个观察者:
- (void) viewDidLoad {
[super viewDidLoad];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(appClosing) name:@"appClosing" object:nil];
}
- (void) dealloc
{
[[NSNotificationCenter defaultCenter] removeObserver:self name:@"appClosing" object:nil];
[super dealloc];
}
- (void) appClosing
{
[self dismissModalViewControllerAnimated:YES];
}
并在您的应用委托中发布通知:
- (void)applicationDidEnterBackground:(UIApplication *)application
{
[[NSNotificationCenter defaultCenter] postNotificationName:@"appClosing" object:nil];
}
于 2010-08-16T08:38:35.640 回答