我想做一个"条款和条件"屏幕,弹出的应用程序的第一次打开。在这个视图中,我将添加一个表示"agree"的按钮,单击它后,代码将执行:
[self dismissViewControllerAnimated:YES completion:nil];
…然后转到应用程序的第一个视图
我目前使用的选项卡栏控制器有4个视图控制器。基本上,我只需要在我的第一个ViewController上的viewWillAppear中有一些功能去检查NSUserDefault key:value。应用程序第一次打开时,它将为零。在他们点击"同意"后,我将其设置为1,并且该位代码将永远不会再次执行。
你能提供一些代码来完成在加载应用程序时从firstViewController的视图路由到这个备用视图控制器的任务吗?
谢谢!
在你的FirstViewController的viewWillAppear方法中,检查NSUserDefaults然后呈现你的TermsViewController。在用户点击TermsViewController中的agree后,设置NSUserDefaults,然后调用
[self.presentingViewController dismissModalViewControllerAnimated:YES]
弹出窗口的使用可能会变得复杂。如果你对Objective-C没什么经验,可以试试下面的代码。
- (void)viewDidLoad {
if ([termsvalue == 0]) {
NSString *msg = [NSString stringWithFormat:@"Do you agree with the terms of use?"];
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"- Confirmation -"
message:msg
delegate:self
cancelButtonTitle:@"Disagree"
otherButtonTitles:@"I agree", nil];
[alert setTag:100];
[alert show];
}
}
- (BOOL)alertViewShouldEnableFirstOtherButton:(UIAlertView *)alertView { // Validation
if ([alertView tag] == 100) {
return YES;
}
}
- (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex { // Go
if ([alertView tag] == 100) {
if (buttonIndex == 1) {
// The user has agreed
}
}
}