-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;
}
在connectionDidFinishLoading中记录'news'。 –
请确保您在主线程上调用'reloadData'。 – rmaddy
你能分享'新闻'的价值!意味着登录并在这里显示。也尝试使用'news = [NSJSONSerialization JSONObjectWithData:data options:0 error:nil];' –