Ios 从欢迎屏幕推送视图控制器时出现问题
我有一个欢迎屏幕,只显示用户第一次打开应用程序时的情况。屏幕工作得很好,但我无法让它在用户单击“完成”时显示正常屏幕 以下是应用程序委托中创建正常屏幕的代码-Ios 从欢迎屏幕推送视图控制器时出现问题,ios,uiviewcontroller,appdelegate,Ios,Uiviewcontroller,Appdelegate,我有一个欢迎屏幕,只显示用户第一次打开应用程序时的情况。屏幕工作得很好,但我无法让它在用户单击“完成”时显示正常屏幕 以下是应用程序委托中创建正常屏幕的代码- - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { self.window = [[UIWindow alloc] initWithFrame:[[UIScree
- (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"];
alertsViewController.title=@"Alerts";
alertsViewController.tabBarItem.title = nil;
//ProfileViewController
ProfileViewController *profileViewController = [[ProfileViewController alloc] init];
profileViewController.tabBarItem.image=[UIImage imageNamed:@"Profile_IconArtboard-1"];
profileViewController.title=@"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;
}
}
看起来,当您显示欢迎屏幕时,您将其推到
UINavigatonController
上。但是,当您单击“完成”时,您将尝试在窗口上设置根视图控制器,而不是从导航控制器中弹出视图控制器。看起来您正在创建FeedViewController
的新实例,而不是使用已创建的实例
另外,您是否检查过它是否正在执行showDone:
方法中的代码?您正在使用=
将UIBarButtonItem
的tintColor
与UIColor
进行比较,但是使用=
只会在它们都是完全相同的UIColor
实例时返回true,而它们可能不是。您需要使用方法isEqual:
来比较两种颜色,因此您可以执行以下操作:
[self.navigationItem.rightBarButtonItem.tintColor isEqual:[UIColor redColor]]
请注意,如果颜色在不同的颜色空间中,对于相同的颜色,这并不总是返回YES
,但大多数情况下,这应该是可行的
此外,您应该考虑将代码从应用程序委托中移出,因为通常“代码>应用程序:DIDFixIdStudioCopyOuts:仅用于启动时需要立即完成的事情。它不应用于初始化一组视图控制器,这些视图控制器只应在显示它们时初始化。
-(BOOL)应用程序:(UIApplication*)应用程序使用选项完成启动:(NSDictionary*)launchOptions(启动选项)
不是一个用来存放初始化应用程序所需的所有slop的槽。