2013-08-04 54 views
0

我已經設置了MySQL數據庫並已解析JSON到我的XCode項目。但是,我在下面的第四行發現了一個THREAD 1: signal SIGABRT錯誤。我認爲這是由於數據庫中「位置」變量之一的空值。這是原因嗎?如果是這樣,我怎樣才能讓它忽略null的值,只是把標籤留空?在此先感謝您的時間。mysql null值拋出xcode錯誤

UILabel *event = (UILabel *)[cell viewWithTag:102]; 
event.text = [dict objectForKey:@"event"]; 

UILabel *location = (UILabel *)[cell viewWithTag:103]; 
location.text = [dict objectForKey:@"location"]; 

回答

0

我感到那空值是不太可能的問題(因爲你可以nil一個UILabeltext屬性刪除文本)。我懷疑,這個問題可以是:

  1. 不知[dict objectForKey:@"location"]可以返回字符串以外的東西,比如一個NSDictionary?我要麼NSLog這個值(或放在一個斷點,並檢查這個值)並確認。或者像下面這樣寫入NSAssert

  2. 不太可能,但我不知道子標籤103是否真的是UILabel?我可能會檢查調試器中的location對象以確定。但是,如果帶有103標記的視圖不是UILabel,那麼您可能會收到錯誤消息。

因此,也許是這樣的:

UILabel *location = (UILabel *)[cell viewWithTag:103]; 
NSAssert([location isKindOfClass:[UILabel class]], @"%s: view with tag 103 is not UILabel: %@", __FUNCTION__, location); 
NSString *locationString = [dict objectForKey:@"location"]; 
NSAssert(locationString == nil || [locationString isKindOfClass:[NSString class]], @"locationString is not nil but not string either: locationString = %@", locationString); 
location.text = locationString; 
+0

嗨,羅布。我試過上面的代碼。我一直得到同樣的錯誤。但是,我現在已確認它是導致錯誤的空值。我在位置變量中輸入了一個值,代碼運行平穩。任何其他想法?謝謝。 – newman

+0

@newman是'locationString'作爲'nil'值還是'[NSNull null]'值返回?當你添加上面的NSAssert值時,是否記錄了任何有趣的內容? – Rob