OStack程序员社区-中国程序员成长平台

标题: ios - 执行 segue 抛出错误 [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-13 11:06
标题: ios - 执行 segue 抛出错误

我在 objective-c 中实现了一些 Json 帖子,在收到信息后,我尝试推送 segue 方法,但它抛出了这个异常

2015-06-25 00:08:33.807 BarApp[1446:109590] -[NSNull length]: unrecognized selector sent to instance 0x37439830

2015-06-25 00:08:33.809 BarApp[1446:109590] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSNull length]: unrecognized selector sent to instance 0x37439830'

这是我的代码

-(void) MakePost: (int)typePost {
    NSString *mainUrl = @"http://url.com/barap/usuario.php";
    NSString *post;
    
    if(typePost == 0) {
        post = [NSString stringWithFormat"?type=0&email=%@&password=%@",self.emailTextField.text, self.passwordTextField.text];
    }else if(typePost == 1){
        post = [NSString stringWithFormat"?type=1&fb_id=%@&nombre=%@&apellido_m=%@&email=%@&profile_picture=%@",fb_id, nombre, apellidoM, email, profilePictureUrl];
    }
    
    NSString *webPostUrl = [NSString stringWithFormat"%@%@", mainUrl, post];
    webPostUrl =[webPostUrl stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
    NSURL *postUrl = [NSURL URLWithString:webPostUrl];
    NSData *userInfo = [[NSData alloc] initWithContentsOfURL:postUrl];

    if(userInfo){
        NSMutableDictionary *userResults = [NSJSONSerialization JSONObjectWithData:userInfo options:NSJSONReadingMutableContainers error:nil];
        if (![userResults[@"id"] isEqualToString""]) {
            [defaults setObject:userResults[@"id"] forKey"userId"];
            NSLog(@"%@", [[NSUserDefaults standardUserDefaults] valueForKey"userId"]);

这是我的代码崩溃的地方!

[self performSegueWithIdentifier"loginSuccess" sender:self];
            
            
            if(typePost == 1){
                [FBSDKAccessToken setCurrentAccessToken:nil];
                [FBSDKProfile setCurrentProfile:nil];
            }
        }
    }else {
        UIAlertView* cError = [[UIAlertView alloc]initWithTitle"Erro!" message"Tuvimos un Error intente mas tarde" delegate:self cancelButtonTitle"Cancelar" otherButtonTitles:@"OK", nil];
        [cError show];
    }
}

- (void)prepareForSegueUIStoryboardSegue *)segue senderid)sender {
    if([[segue identifier] isEqualToString:@"loginSuccess"]) {
        [segue destinationViewController];
    }
}



Best Answer-推荐答案


该消息表明在 NSNull 对象上调用了 length 方法。因为 length 方法很可能会在 NSString

上调用

查看此链接

-[NSNull length]: unrecognized selector sent to JSON objects

关于ios - 执行 segue 抛出错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31041743/






欢迎光临 OStack程序员社区-中国程序员成长平台 (https://ostack.cn/) Powered by Discuz! X3.4