-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];' –