Ios 在objective-C中成功登录后隐藏登录屏幕
我们需要更改Ios 在objective-C中成功登录后隐藏登录屏幕,ios,objective-c,viewcontroller,appdelegate,initwithnibname,Ios,Objective C,Viewcontroller,Appdelegate,Initwithnibname,我们需要更改StartViewController。在我们的应用程序中,StartViewController位于Login.h。登录成功后,接下来的时间不需要显示login.h。因此,我们尝试在AppDelegate中更改视图,如下所示: - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { [NSThread slee
StartViewController
。在我们的应用程序中,StartViewController
位于Login.h
。登录成功后,接下来的时间不需要显示login.h
。因此,我们尝试在AppDelegate
中更改视图
,如下所示:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
[NSThread sleepForTimeInterval:3.0];
NSString *myString = [[NSUserDefaults standardUserDefaults]stringForKey:@"loginpin"];
if (myString.length != 0) {
NSLog(@"Select Items %@",myString);
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.loginViewController = (ViewController*)[ourStoryBoard instantiateViewControllerWithIdentifier:@"Main"];
self.window.rootViewController = self.loginViewController;
self.window.backgroundColor = [UIColor grayColor];
[self.window makeKeyAndVisible];
}
return YES;
}
但我们在控制台中得到了以下信息:
应用程序窗口应在应用程序启动结束时具有根视图控制器
然后它显示为空屏幕。请引导我。代码有什么问题?登录成功后,是否有其他方法隐藏登录屏幕?我想是这样的
[NSThread sleepForTimeInterval:3.0]代码>此代码导致问题
请尝试删除上述代码并重试。如果您需要更多时间来完成加载,则应创建另一个类似于您可以控制的初始屏幕的视图
还要检查序列图像板中是否已将任何一个视图控制器设置为初始视图控制器
应用程序第一次运行时,loginpin
内将没有任何内容。下面的检查将始终失败
NSString *myString = [[NSUserDefaults standardUserDefaults]stringForKey:@"loginpin"];
if (myString.length != 0)
{
//...
}
你也没有其他条款。如果此检查失败,应用程序将不显示任何内容。你需要写一些东西,比如:
if (myString.length != 0)
{
// dispaly homepage
}
else
{
// display login
}
另外请注意运行[NSThread sleepForTimeInterval:3.0]代码>在回调中是非常糟糕的做法。如果需要延迟加载,则应创建新的启动屏幕。如果此回调时间过长,iOS将关闭您的应用程序。请尝试此操作
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
[NSThread sleepForTimeInterval:3.0];
NSString *myString = [[NSUserDefaults standardUserDefaults]stringForKey:@"loginpin"];
if (myString.length != 0)
{
NSLog(@"Select Items %@",myString);
self.loginViewController = (ViewController*)[ourStoryBoard instantiateViewControllerWithIdentifier:@"Main"];
self.window.rootViewController = self.loginViewController;
}
else
{
YourHomeViewController *homeView = [ourStoryBoard instantiateViewControllerWithIdentifier:@"YourHomeViewIdentifier"];
self.window.rootViewController = homeView;
}
return YES;
}
满足您需求的解决方案:
添加启动屏幕
在启动屏幕上的viewDidLoad
方法显示登录屏幕和您的计时
- (void)viewDidLoad
{
//Method to show login screen with dealy
[self performSelector:@selector(showLoginVC) withObject:nil afterDelay:2.0f];
}
注意:如果您想这是在成功登录后发生的吗?NSLog工作正常吗?您是否检查self.loginViewController是否为零?希望此链接对您有用:不要忘记对答案进行评论或回复评论。如果一个或多个答案解决了您的问题,请进行投票或将其标记为最佳答案(如果适用)。请不要将问题留待讨论,因为其他面临相同问题的人不知道是什么解决了您的问题
-(void)showLoginVC
{
//get current loginVC object
UINavigationController *objUINavigationController = objectHere
if (objUINavigationController)
{
//set in rootViewController of UIWindow
[objAppDelegate.window setRootViewController:objUINavigationController];
}
}