2013-12-11 111 views
-1

我試圖填充JSON一個UITableView,但是當我建立連接後重裝我的表的數據會引起我的應用程序崩潰,錯誤代碼UITableView的JSON reloadData

「主題1:EXC_BAD-ACCESS (代碼= 1,地址= 0x0040da5)」

這裏是我的代碼:

-(void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response 
{ 
    data = [[NSMutableData alloc] init]; 
} 

-(void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)theData { 
[data appendData:theData]; 
} 


-(void)connectionDidFinishLoading:(NSURLConnection *)connection { 

[UIApplication sharedApplication].networkActivityIndicatorVisible = NO; 

news = [NSJSONSerialization JSONObjectWithData:data options:nil error:nil]; 
[mainTableView reloadData]; 


} 

-(void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error { 

    UIAlertView *errorView = [[UIAlertView alloc] initWithTitle:@"Error" message:@"Could not gather data, please make sure you're connected to either 3G or Wi-F" delegate:nil cancelButtonTitle:@"Dismiss" otherButtonTitles:nil, nil]; 
[errorView show]; 
[UIApplication sharedApplication].networkActivityIndicatorVisible = NO; 

} 
+0

在connectionDidFinishLoading中記錄'news'。 –

+0

請確保您在主線程上調用'reloadData'。 – rmaddy

+0

你能分享'新聞'的價值!意味着登錄並在這裏顯示。也嘗試使用'news = [NSJSONSerialization JSONObjectWithData:data options:0 error:nil];' –

回答

0

1>你確定你得到的消息通過你的表視圖如預期?

2>你叫重裝數據之前設置的消息到你的表中的數據源

3>請確保您是從字典中的cellForIndexPath方法

主要觀察提取正確的價值觀是有在cellForRowAtIndexPath和訪問新聞數組中出現錯誤。請檢查

+0

事實證明我有我的cellForIndexPath方法的錯誤,感謝您的幫助! – user2843105