Я пытаюсь заполнить UITableView с JSON, но, когда я перезагрузить данные моей таблицы после выполнения соединения он вызывает мое приложение к сбою, с кодом ошибки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;
}
журнал 'news' в связиDidFinishLoading. –
Убедитесь, что вы вызываете 'reloadData' в основном потоке. – rmaddy
Вы могли бы поделиться ценностью «новости»! означает журнал и показать здесь. Также попробуйте использовать 'news = [NSJSONSerialization JSONObjectWithData: параметры данных: 0 error: nil];' –