2016-04-05 144 views
-1

這似乎應該是非常簡單 - 但唉,我得到一個崩潰。我只是想爲我設置的UILabel從USERS_NAME場返回的文本:終止應用程序由於未被捕獲>異常'NSInvalidArgumentException'

.M

NSMutableDictionary *viewParams = [NSMutableDictionary new]; 
[viewParams setValue:@"u000" forKey:@"view_name"]; 
[DIOSView viewGet:viewParams success:^(AFHTTPRequestOperation *operation, id responseObject) { 


    self.userData = [responseObject mutableCopy]; 

    self.username.text = [self.userData objectForKey:@"users_name"]; 

    dispatch_async(dispatch_get_main_queue(), ^(void){ 

    }); 


} failure:^(AFHTTPRequestOperation *operation, NSError *error) { 
    NSLog(@"Failure: %@", [error localizedDescription]); 
}]; 

控制檯返回數據:

2016-04-05 12:25:36.877 [1331:350069] This is the Other User Data (
     { 
     address = "Vancouver"; 
     userbio = "There is currently no bio available for this user. If you have added your bio, and require assistance, please contact the Team."; 
     "users_name" = Brittany; 
    }, 

也就是說,這條線路導致崩潰:

self.username.text = [self.userData objectForKey:@"users_name"]; 

這是錯誤:

2016-04-05 12:25:36.878 [1331:350069] -[__NSCFArray objectForKey:]: unrecognized selector sent to instance 0x15a23c100 2016-04-05 12:25:36.881 [1331:350069] * Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFArray objectForKey:]: unrecognized selector sent to instance 0x15a23c100' * First throw call stack: (0x181d51900 0x1813bff80 0x181d5861c 0x181d555b8 0x181c5968c 0x1000cce9c 0x1000c72bc 0x1000d3cc4 0x100459bf0 0x100459bb0 0x10045f658 0x181d08bb0 0x181d06a18 0x181c35680 0x183144088 0x186aacd90 0x1000d4c88 0x1817d68b8) libc++abi.dylib: terminating with uncaught exception of type NSException

我會如何解決這個問題?它似乎應該是簡單的...

+0

你可以嘗試userData [@「users_name」]?並且userData是NSDictionary?如果失敗,請嘗試記錄userData [@「users_name」]。 –

+2

它看起來像它認爲userData是一個數組(原因是' - [NSCFArray objectForKey:]')我會嘗試放置一個斷點,並驗證'userData'實際上是一個字典,而不是一個數組 –

+0

@TejaNandamuri是的,做這種方式失敗了。同樣的崩潰錯誤。 – Brittany

回答

0

我想userData是一個數組類型。數組沒有鍵值。 嘗試:
[[self.userData objectAtIndex:0] objectForKey:@"users_name"];

+0

我得到的錯誤:「沒有可見@interace爲'NSDictionary'聲明選擇器objectAtIndex當我輸入此 – Brittany

+0

我懷疑這是因爲你聲明userData作爲一個NSDictionary up top。更改類型爲NSArray,然後我懷疑將工作。 –

相關問題