[英]Which one is efficient in terms of performance - Object of AppDelegate or Macro of AppDelegate?
[英]Displaying terms and conditions on AppDelegate
我想首先在appdelegate
上显示条款的UIAlertController
,如果用户单击“同意”,则可以执行我的viewController,但是如果用户单击“取消”,则该应用程序应保留在启动屏幕上。 我有以下代码,但它显示了没有uinavigationController且没有功能的viewController。
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
userDefaults = [NSUserDefaults standardUserDefaults];
if (![userDefaults boolForKey:@"TermsAndConditions"]) {
_window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
_window.rootViewController = [[UIViewController alloc] init];
_window.windowLevel = UIWindowLevelAlert;
_window.backgroundColor = [UIColor prosenseWhiteColor];
UIImageView *windowImage = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"Defaulte"]];
[windowImage setFrame:[UIScreen mainScreen].bounds];
[windowImage setContentMode:UIViewContentModeScaleAspectFit];
[_window addSubview:windowImage];
[_window makeKeyAndVisible];
NSString *path = [[NSBundle mainBundle] pathForResource:@"termsAndConditions" ofType:@"txt"];
NSString *tsAndCs = [NSString stringWithContentsOfFile:path encoding:NSUTF8StringEncoding error:NULL];
UIAlertController *termsAndConditionsController = [UIAlertController alertControllerWithTitle:@"Terms and conditions" message:tsAndCs preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *agree = [UIAlertAction actionWithTitle:@"Agree" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action){
[self.window.rootViewController dismissViewControllerAnimated:YES completion:nil];
[userDefaults setBool:YES forKey:@"TermsAndConditions"];
[userDefaults synchronize];
UIStoryboard *st_board = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
PTPdfFileListViewController *pdfFileListView = (PTPdfFileListViewController*)[st_board instantiateViewControllerWithIdentifier:@"PTPdfFileListViewController"];
self.window.windowLevel = UIWindowLevelNormal;
[self.window makeKeyAndVisible];
[(UINavigationController*)self.window.rootViewController presentViewController:pdfFileListView animated:NO completion:nil];
}];
UIAlertAction *cancel = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action){
NSLog(@"Cancel");
}];
[termsAndConditionsController addAction:cancel];
[termsAndConditionsController addAction:agree];
[_window.rootViewController presentViewController:termsAndConditionsController animated:YES completion:nil];
}else {
NSLog(@"accepted terms already");
}
}
我做错了什么?
您应该以根用户身份将PTPdfFileListViewController嵌入UINavigationController中,并提供该UINavigationController。
尝试使用pushViewController
代替presentViewController
,它将出现在主应用程序的导航控制器中。
用户将可以返回,因此我不确定这是您正在寻找的解决方案。
不带返回按钮的解决方案:
[(UINavigationController*)self.window.rootViewController setViewControllers:@[pdfFileListView] animated:NO];
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.