在 iOS4 之前,我的应用程序的初始视图控制器将检查 viewWillAppear 中的密码开/关设置变量,如果设置为打开,则显示一个模式密码屏幕,该屏幕将一直保留在那里,直到输入正确的密码或按下主页按钮。
对于 iOS4,如果我的应用程序一直在后台运行,我希望用户感到放心,因为如果他们将手机交给某人使用,则应用程序中包含的数据将无法轻松访问。
由于应用程序可以返回到任何屏幕(应用程序上次所在的屏幕),因此我想我应该在整个地方使用 UIApplicationWillEnterForegroundNotification 和本地选择器(重复的 EnterPasscode 方法),每个选择器都有正确的视图控制器来根据本地屏幕,但必须有更好的方法。
我在这里可能有一个轻微的概念误解。有人可以建议另一种方法或推动我进行下一步吗?我可以将其作为共享方法,但仍然知道要推送的正确本地视图控制器吗?
Thanks
编辑/更新:
简短版本:它有效,但可能还有更好的方法(感谢任何帮助)...
我使用视图控制器创建了一个标准单例。
PasscodeView.h 包含:
UIViewController *viewController;
@property (nonatomic, retain) UIViewController *viewController;
PasscodeView.m 包含:
@synthesize viewController;
我把它放在 AppDelegate 中:
-(void)applicationWillEnterForeground:(UIApplication*)application {
PasscodeView *passcodeView = [PasscodeView sharedDataManager];
UIViewController *currentController = [passcodeView viewController];
NSLog(@"%@", currentController); //testing
EnterPasscode *passcodeInput = [[EnterPasscode alloc] initWithNibName:@"Passcode" bundle:nil];
[currentController presentModalViewController:passcodeInput animated:NO];
[passcodeInput release];
}
以及我所有 viewDidLoad 中的以下内容,在进入每个屏幕时更新当前视图控制器(只有 2 行,但似乎仍然有更好的方法):
PasscodeView *passcodeView = [PasscodeView sharedSingleton];
passcodeView.viewController = [[self navigationController] visibleViewController];
我希望有一种方法可以从 applicationWillEnterForeground 获取当前视图控制器,但我找不到它 - 仍然感谢这里的任何帮助。
为了保持一致性,我更改了一行并添加了一行以获得导航栏以匹配应用程序的其余部分并包含标题。
UINavigationController *passcodeNavigationController = [[UINavigationController alloc] initWithRootViewController:passcodeInput];
[currentController presentModalViewController: passcodeNavigationController animated:NO];