2013-12-11 114 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