我最近完成了名为 Bird Watching 的关于表视图的苹果教程,并且效果很好。但是,我现在正试图通过添加一个编辑按钮来进一步处理它,并且似乎遇到了问题。
下面是 MasterViewController 用来创建我的表的代码。这工作正常。
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath (NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"BirdSightingCell";
static NSDateFormatter *formatter = nil;
if(formatter == nil){
formatter = [[NSDateFormatter alloc] init];
[formatter setDateStyle:NSDateFormatterMediumStyle];
}
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
BirdSighting *sightingAtIndex = [self.dataController objectInListAtIndex:indexPath.row];
[[cell textLabel]setText:sightingAtIndex.name];
[[cell detailTextLabel]setText:[formatter stringFromDate:(NSDate *)sightingAtIndex.date]];
return cell;
}
我已经尝试使用其中的一些代码来使编辑按钮正常工作,下面是我创建的。这不起作用,我不知道如何解决它。
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
if (editingStyle == UITableViewCellEditingStyleDelete) {
BirdSighting *sightingAtIndex = [self.dataController removeObjectAtIndex:indexPath.row];
[tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
} else if (editingStyle == UITableViewCellEditingStyleInsert) {
// Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view.
}
}
我收到的错误消息之一是“BirdSightingDataController 没有可见的@interface 声明选择器 removeObjectAtIndex。