【问题标题】:Pushing to another ViewController Error推送到另一个 ViewController 错误
【发布时间】:2014-05-31 09:11:22
【问题描述】:

在我的应用程序中,我实现了访问令牌逻辑。登录后,在我的仪表板的 ViewDidLoad 中,正在调用 Web 服务以获取企业列表。在

  • (void)connectionDidFinishLoading:(NSURLConnection *)connection

方法,正在解析值。如果 AT 标签(访问令牌)已过期(我会收到一条消息“访问令牌无效),我想调用登录​​页面(会话已过期)。但我在控制台中收到错误

对 .

并且控件保留在我的仪表板中。

NSString *OSString = [jsonMain valueForKey:@"OS"];
    NSString *errorString = [jsonMain valueForKey:@"EM"];

    if([OSString isEqualToString:@"Success"])
    {
       // other parsing stuff
    }
    else
    {
        if([errorString isEqualToString:@"Access Token is invalid"])
        {
            appDelegate.loginMsgStr = @"Session Expired";

            Login *login = [[Login alloc] init];
            [self.navigationController pushViewController:login animated:YES];
        }
        else
        {
            UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Alert!"
                                                            message:errorString
                                                           delegate:self
                                                  cancelButtonTitle:@"OK"
                                                  otherButtonTitles:nil];
            [alert show];
        }
    }

【问题讨论】:

  • 如果您可以显示一些关于您正在使用什么或如何尝试返回登录页面的代码,那么我可以尝试并提供帮助。
  • @iOSDev : 我已经更新了帖子...
  • 在 ViewControllers 生命周期的哪个阶段你会这样做?登录是否使用 .xib?查看此帖子stackoverflow.com/questions/6809593/…

标签: ios uinavigationcontroller pushviewcontroller


【解决方案1】:

如果您正在使用情节提要,请使用

UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];
    Login * login = (Login *)[storyboard instantiateViewControllerWithIdentifier:@"Loginview"];
    [self.navigationController pushViewController:login animated:YES];

如果您使用自定义导航,请使用

Login *login=[[Login alloc]initWithNibName:@"Login" bundle:[NSBundle mainBundle]];
     [self.navigationController pushViewController:login animated:YES];

【讨论】:

    【解决方案2】:

    如果 LoginView 是您的 RootViewController,请在您的

    中使用此代码

    (void)connectionDidFinishLoading:(NSURLConnection *)connection

    方法:

    [self.navigationController popToRootViewControllerAnimated:YES];

    如果这行得通,请告诉我。

    干杯。

    【讨论】:

    • 此链接也可能有助于消除您的疑虑。 stackoverflow.com/questions/9088465/…
    • 它没有工作 frnd.. 使用你的代码后,我没有在控制台中收到该错误,但仍然控制在仪表板中。它没有进入登录页面。
    • 如果它仍然在同一页面中,您可以尝试使用断点进行调试并检查登录视图的初始化位置。你能告诉我登录视图是否已经在堆栈中或者你需要推送到登录视图吗???
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-05-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-06-11
    相关资源
    最近更新 更多