的iOS4之前,我的应用程序的初始视图控制器将检查在viewWillAppear中,如果设置变量/关设定密码,呈现模式密码屏幕将呆在那里,直到输入正确的密码或主页按钮被按下。使用applicationwillenterforeground的密码屏幕
随着iOS4的,如果我的应用程序一直在后台,我想包含在数据中的应用是不容易接触,如果他们要交出自己的手机给别人使用的用户感到舒适。由于应用程序可以返回到任何屏幕(该应用程序最后一个屏幕),我想我会在本地选择器(重复的enterPasscode方法)遍布整个地方使用UIApplicationWillEnterForegroundNotification,每个屏幕都有正确的视图控制器基于本地屏幕推送,但必须有更好的方法。
我在这里可以具有轻微的概念误解。有人可以提出另一种方法,或者推动我继续下一步。我可以把它作为一个共享方法,但仍然知道正确的本地视图控制器推送?
感谢
编辑/ UPDATE:
短版:它的工作原理,但可能仍有可能是一个更好的方法(能够理解的任何帮助)...
我创建了一个标准单用一个视图控制器。
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];
这是我开始的地方,但不知道要为视图控制器放置什么 - 我会给这个想法然后试一试。 – 2010-08-08 18:02:39
请参阅上面的编辑。 – 2010-08-08 18:23:09
我从概念上理解你正在尝试的 - 在这里提供一个密码屏幕而不是在每个视图控制器 - 看起来它应该工作,但事实并非如此。完全按照原样复制代码(将PasscodeInputController更改为EnterPasscode),生成良好,没有错误,没有警告,但没有出现。我最初并不熟悉UIWindow的rootViewController属性,但在读完它之后,它看起来应该可以工作 - 尽管找不到任何其他示例。我试了一些其他的东西 - 尝试在那里使用navcontroller,尝试了子视图,makeKeyAndVisible但没有。 – 2010-08-09 03:29:25