繁体   English   中英

执行 segue 抛出错误

[英]perform segue throws error

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

2015-06-25 00:08:33.807 BarApp[1446:109590]-[NSNull 长度]:无法识别的选择器发送到实例 0x37439830

2015-06-25 00:08:33.809 BarApp[1446:109590] *** 由于未捕获的异常“NSInvalidArgumentException”而终止应用程序,原因:“-[NSNull 长度]:无法识别的选择器发送到实例 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)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    if([[segue identifier] isEqualToString:@"loginSuccess"]) {
        [segue destinationViewController];
    }
}

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

检查此链接

-[NSNull 长度]:无法识别的选择器发送到 JSON 对象

你应该检查 [NSNULL null]。 您在 Json 请求中收到一个或多个 NSNUll 值。

检查这可能是你需要的 - [NSNull isEqualToString:]

这些行将帮助您更多- NSMutableDictionary *dicAfterRemovingNull = [NSMutableDictionary dictionaryWithDictionary: yourDictionary]; // 如果字典和数组用 MutableArray 改变这一行

for(NSString *key in [dicAfterRemovingNull allKeys])
{
    const id object = [dicAfterRemovingNull objectForKey:key];
    if(object == [NSNull null])
    {
        [dicAfterRemovingNull setValue:@"whatever you want" forKey:key];
    }
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM