我运行这个功能:不能运行在Objective-C函数
- (void)insertRows {
[_objects insertObject:[NSDate date] atIndex:0];
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:0 inSection:0];
[self.tableView insertRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationAutomatic];
}
,它必须运行此功能
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell" forIndexPath:indexPath];
NSDate *object = _objects[indexPath.row];
cell.textLabel.text = [object description];
return cell;
}
,但此功能无法运行......请帮助如何运行的tableView ...功能
- (IBAction)insertObject {
[[MasterViewController alloc] insertRows];
}
- 此代码运行insertRows,我用的断点
检查此- (IBAction)insertObject:(id)sender {
[_objects insertObject:[NSDate date] atIndex:0];
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:0 inSection:0];
[self.tableView insertRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationAutomatic];
NSLog(@"log:insert-indexPath: %i",indexPath.row);
NSDate *object = _objects[indexPath.row];
NSLog(@"log:insert-object %@",object.description);
}
-works与它,为什么?
可以'self.tableview'为零? – Chuck
Chuck,no ...因为如果我通过IBAction(tap button)运行insertRow ... tableview ...作品... – EarthUser
因此可能你没有调用该方法。 –