![](/img/trans.png)
[英]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.