簡體   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