我有一個歡迎屏幕,只顯示用戶第一次打開該應用程序。屏幕效果很好,但當用戶點擊完成後,我無法顯示正常屏幕。從歡迎屏幕推動視圖控制器時出現問題
這裏是應用程序委託代碼來創建正常畫面 -
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] ;
if([[NSUserDefaults standardUserDefaults] boolForKey:@"TermsAccepted"]!=YES)
{
[[NSUserDefaults standardUserDefaults] setBool:NO forKey:@"TermsAccepted"];
}
// Override point for customization after application launch.
FeedViewController *feedViewController = [[FeedViewController alloc] init];
UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:feedViewController];
[self.window addSubview:nav.view];
self.window.rootViewController = nav;
[self.window makeKeyAndVisible];
self.tabBarController = [[UITabBarController alloc] init];
[[UITabBar appearance] setTintColor:[UIColor redColor]];
// FeedViewController
feedViewController=[[FeedViewController alloc] init];
feedViewController.tabBarItem.image=[UIImage imageNamed:@"Describe-Home_Icon_NormalArtboard-1"];
feedViewController.title = @"Timeline";
feedViewController.tabBarItem.title = nil;
//TodayViewController
TodayViewController *todayViewController = [[TodayViewController alloc] init];
todayViewController.tabBarItem.image = [UIImage imageNamed:@"Today_Icon"];
todayViewController.title = @"Today";
todayViewController.tabBarItem.title = nil;
//CreateViewController
self.createViewController = [[CreateViewController alloc] init];
self.createViewController.tabBarItem.image = [UIImage imageNamed:@"Create_Icon"];
self.createViewController.title = @"Create";
self.createViewController.tabBarItem.title = nil;
//AlertViewController
AlertsViewController *alertsViewController = [[AlertsViewController alloc] init];
alertsViewController.tabBarItem.image=[UIImage imageNamed:@"Alerts_IconArtboard-1"];
[email protected]"Alerts";
alertsViewController.tabBarItem.title = nil;
//ProfileViewController
ProfileViewController *profileViewController = [[ProfileViewController alloc] init];
profileViewController.tabBarItem.image=[UIImage imageNamed:@"Profile_IconArtboard-1"];
[email protected]"Profile";
profileViewController.tabBarItem.title = nil;
NSMutableArray *tabBarViewControllers = [[NSMutableArray alloc] initWithCapacity:2];
self.tabBarController = [[UITabBarController alloc] init];
UINavigationController *feedNavigationController = [[UINavigationController alloc] initWithRootViewController:feedViewController];
[tabBarViewControllers addObject:feedNavigationController];
feedNavigationController = nil;
UINavigationController *todayNavigationController = [[UINavigationController alloc] initWithRootViewController:todayViewController];
[tabBarViewControllers addObject:todayNavigationController];
todayNavigationController = nil;
UINavigationController *createNavigationController = [[UINavigationController alloc] initWithRootViewController:self.createViewController];
[tabBarViewControllers addObject:createNavigationController];
createNavigationController = nil;
UINavigationController *alertsNavigationController = [[UINavigationController alloc] initWithRootViewController:alertsViewController];
[tabBarViewControllers addObject:alertsNavigationController];
alertsNavigationController = nil;
UINavigationController *profileNavigationController = [[UINavigationController alloc] initWithRootViewController:profileViewController];
[tabBarViewControllers addObject:profileNavigationController];
profileNavigationController = nil;
self.tabBarController.viewControllers = tabBarViewControllers;
tabBarViewControllers = nil;
[self.window addSubview:self.tabBarController.view];
return YES;
}
在feedViewController推歡迎視圖控制器 -
if ([[NSUserDefaults standardUserDefaults] boolForKey:@"TermsAccepted"]){
NSLog(@"Second time opening the app");
}
else{
WelcomeViewController *welcomeViewController = [[WelcomeViewController alloc] init];
[self.navigationController pushViewController:welcomeViewController animated:NO];
}
要回去喂,是不是工作 -
-(void)showDone:(UIButton *)sender {
if (self.navigationItem.rightBarButtonItem.tintColor == [UIColor redColor]) {
[[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"TermsAccepted"];
FeedViewController *feedViewController = [[FeedViewController alloc] init];
[[UIApplication sharedApplication] keyWindow].rootViewController = feedViewController;
self.tabBarController.tabBar.hidden = NO;
self.navigationController.navigationBar.hidden = NO;
}
}
' - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions'不是設計用於容納初始化應用程序所需的所有操作的槽。 – nhgrif