Login page goes to main UITabBar view even with incorrect login info

天涯浪子 提交于 2019-12-13 06:24:29

问题


Ok so I'm linked to a server and I know for a fact that I have all the code there correct. But something seems to be wrong with this code:

-(void)connectionDidFinishLoading:(NSURLConnection *)connection {
    NSString* responseString = [[NSString alloc] initWithData:_responseData encoding:NSUTF8StringEncoding];

    /*Succesful Login*/
    if([responseString isEqualToString:@"success"]){

        [self performSegueWithIdentifier:@"LoginHomeToMain" sender:self];

        NSLog(@"Succesful login.");
    }

    /*Deactivated Account*/
    else if([responseString isEqualToString:@"disabled account"]){

    }

    /*Incorrect username and password.*/
    else if([responseString isEqualToString:@"incorrect"]){
        NSLog(@"Incorrect username and (or) password.");
    }

    /*GET request*/
    else if([responseString isEqualToString:@"get"]){

    }
}

So I think you can ignore the 2nd and 4th else if's but here's the problem: When I try a user and pass that I know does not exist in the server, it still segues me to the main tab bar view. Am I supposed to reload the login page's view for the "incorrect" logic, or is my segue wrong? P.S. The segue is simply linked from a login button to the main tab bar view, and is modal.

Also, I keep getting this error message in the debugger:

"Unbalanced calls to begin/end appearance transitions for ."

Any help is greatly appreciated, Thanks!


回答1:


If you want to perform a segue conditionally, you need to link the segue from the origin view controller to the destination view controller.

Do not link the segue from a UI element such as a button. (if you want to only perform the segue conditionally, that is)

Changing your segue's origin connection from the button to the view controller will fix your problem without changing a line of code.


Personally, I've just started always linking from view controller. It's easy enough to write the one line of code to perform the segue, and you never know when you'll have to write some sort of conditional logic around it later. So it's probably good to just get into the habit of doing it this way.



来源:https://stackoverflow.com/questions/20715257/login-page-goes-to-main-uitabbar-view-even-with-incorrect-login-info

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!