如何將getnewdata的結果添加到我現有的tableView中使用insertRowsAtIndexPaths?我找到了幾個例子,但無法弄清楚。如何使用insertRowsAtIndexPaths將數組內的字典添加到UItableview?
- (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;
}
你必須是一個Ruby開發者:-)。 Objective-c約定是camelCase。 – danh 2012-04-28 19:13:54