Я пытаюсь загрузить JSON с сервера и затем отобразить его в UITableView. Запрос выполняется нормально, однако, когда я пытаюсь добавить данные в табличное представление, приложение вылетает при вызове, затем вызывается метод [tableView reloadData]
У меня есть ссылка на переменную jsonArray
в методах UITableView, чтобы TableView отображал содержимое этой переменной. Это лучший способ сделать это и что я делаю не так?
Соединение
NSURLConnection *theConnection=[[NSURLConnection alloc] initWithRequest:theRequest delegate:self];
Основной HTTP-обратный вызов
- (void)connectionDidFinishLoading:(NSURLConnection *)connection
{
[connection release];
NSString *responseString = [[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding];
[responseData release];
//Declare the parser
SBJsonParser *parser = [[SBJsonParser alloc] init];
jsonArray = [parser objectWithString:responseString];
[tableView reloadData];
[parser release];
[responseString release];
}
Error
2011-07-07 14:42:56.923 Viiad[16370:207] -[__NSSet0 objectAtIndex:]: unrecognized selector sent to instance 0x5a4a0b0
2011-07-07 14:42:56.925 Viiad[16370:207] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSSet0 objectAtIndex:]: unrecognized selector sent to instance 0x5a4a0b0'
EDIT
UITableViewMethods
// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}
NSArray *results = [[jsonArray valueForKey:@"Rows"] valueForKey:@"name"];
cell.textLabel.text = (NSString *)[results objectAtIndex:indexPath.row];
return cell;
}