如何使用insertRowsAtIndexPaths将getnewdata的结果添加到现有的 tableView 中?我找到了几个例子,但无法弄清楚。
- (void)getfirstdata {
[...] //get JSON data
self.data = jsonResult; //a dictionary inside of an array
[self.tableView reloadData];
}
- (void)getnewdata {
[...] //get new JSON data which has to be added to top of the table
self.data = jsonnewResult; //a dictionary inside of an array
[self.tableView reloadData];
}
(UITableViewCell *) tableView: (UITableView *) table_view cellForRowAtIndexPath: (NSIndexPath *) index_path
static NSString *CellIdentifier = @"Cell";
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
}
id celldata = [self.data objectAtIndex:[index_path row]];
cell.textLabel.text = [celldata valueForKeyPath:@"user.name"];
cell.detailTextLabel.text = [celldata objectForKey:@"text"];
return cell;
}