Iphone 如何使用InsertRowsatindExpath将数组内部的字典添加到UItableview?
如何使用insertRowsAtIndexPaths将getnewdata的结果添加到现有的tableView中?我找到了几个例子,但无法理解Iphone 如何使用InsertRowsatindExpath将数组内部的字典添加到UItableview?,iphone,arrays,uitableview,dictionary,cell,Iphone,Arrays,Uitableview,Dictionary,Cell,如何使用insertRowsAtIndexPaths将getnewdata的结果添加到现有的tableView中?我找到了几个例子,但无法理解 - (void)getfirstdata { [...] //get JSON data self.data = jsonResult; //a dictionary inside of an array [self.tableView reloadData]; } - (void)getnewdata { [.
- (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;
}
对于“获取新信息”,您希望添加到数据中,因此
- (void)getnewdata {
[...] //get new JSON data which has to be added to top of the table
[self.data addObjectsFromArray:jsonResult];
[self.tableView reloadData];
}
确保self.data是NSMutableArray
编辑
我突然想到,你可能想把新数据放在上面
NSMutableArray *newModel = [NSMutableArray arrayWithArray:jsonResult];
[newModel addObjectsFromArray:self.data];
self.data = newModel;
您必须是ruby开发人员:-)。Objective-c约定是camelCase。谢谢,这很好用,可惜没有insertRowsAtIndexLevel