我想先顯示UIAlertController
條款appdelegate
首先,如果用戶點擊「同意」,我就可以將我的視圖控制器拖到我的視圖控制器,但是如果用戶點擊「取消」,那麼應用程序應該保持在啓動畫面上。我有下面的代碼,但它顯示我的viewController沒有uinavigationController和沒有功能。在AppDelegate上顯示條款和條件
- (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");
}
}
什麼是我做錯了?
希望你設置你的 「的viewController」 作爲初始視圖控制器。這可能是空白視圖控制器在啓動屏幕後顯示的原因。你能檢查一下嗎?謝謝。 –
爲什麼你讓這太複雜。只要創建一個UIveiw,然後顯示在rootviewcontroller上,一旦該accdept不加載它。 –
@Nitin Gohel我試過了,我認爲可能有更好的方法來做,因爲你建議先顯示rootview 2秒,然後顯示uiview的條款和條件 –