Iphone UITableView不会进入编辑模式,也不会进行编辑!

Iphone UITableView不会进入编辑模式,也不会进行编辑!,iphone,objective-c,uitableview,Iphone,Objective C,Uitableview,我几乎没有在做一个新项目。主要结构是RootViewController中的tableView,其中一些行向用户显示实际状态和一些信息。我现在正在使用编辑模式,但该模式不起作用 导航栏中有一个按钮,它调用“编辑”,下面是代码: - (void)edit { NSLog(@"Edit pressed"); if (edit) { NSLog(@"Deactivate edit\n"); edit = NO; self.navigati

我几乎没有在做一个新项目。主要结构是RootViewController中的tableView,其中一些行向用户显示实际状态和一些信息。我现在正在使用编辑模式,但该模式不起作用

导航栏中有一个按钮,它调用“编辑”,下面是代码:

- (void)edit {
    NSLog(@"Edit pressed");
    if (edit) {
        NSLog(@"Deactivate edit\n");
        edit = NO;
        self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"Bearbeiten" style:UIBarButtonItemStyleBordered target:self action:@selector(edit)];
        [contentTableView setEditing:NO animated:YES];
    } else {
        NSLog(@"Activate edit\n");
        edit = YES;
        self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"Fertig" style:UIBarButtonItemStyleDone target:self action:@selector(edit)];
        [contentTableView setEditing:YES animated:YES];
    }
}
我的viewController是UITableViewController的一个子类,contentTableView不是nil。。。我实施了以下方法:

- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)sourceIndexPath toIndexPath:(NSIndexPath *)destinationIndexPath {
    NSMutableDictionary *oldDict = [[NSMutableDictionary alloc] initWithDictionary:[saver read]];
    NSDictionary *movingDict = [[oldDict objectForKey:@"content"] objectAtIndex:sourceIndexPath.row];
    [[oldDict objectForKey:@"content"] removeObjectAtIndex:sourceIndexPath.row];
    [[oldDict objectForKey:@"content"] insertObject:movingDict atIndex:destinationIndexPath.row];
    [saver write:oldDict];
}

- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {

    NSMutableDictionary *oldDict = [[NSMutableDictionary alloc] initWithDictionary:[saver read]];
    [[oldDict objectForKey:@"content"] removeObjectAtIndex:indexPath.row];
    [saver write:oldDict];

    [contentTableView beginUpdates];
    [contentTableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade]; //This doesn't work!
    [contentTableView endUpdates];

}

- (NSString *)tableView:(UITableView *)tableView titleForDeleteConfirmationButtonForRowAtIndexPath:(NSIndexPath *)indexPath {
    return @"Entfernen";
}

- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath
{
    return YES;
}
我从另一个项目中复制了这篇文章,并修改了部分代码,但主要内容我没有触及

会发生什么

当我按下Edit‘Bearbeiten’时,会调用函数Edit。它将按钮替换为“Fertig”,并写入正确的日志:

> 2011-04-27 13:35:44.338 MyApp[1113:207] Edit pressed
> 2011-04-27 13:35:44.339 MyApp[1113:207] Activate edit
如果我在单元格上滑动,按钮Remove'Entfernen'出现,当我按下它时,按钮消失,但行仍然存在,但它已从内容中删除

有人知道我哪里做错了什么或我哪里忘了什么吗

提前谢谢你,mavrick3

编辑1:


我忘了说:方法[tableView reloadData];不在分区中调用numberOfRowsInSection

这些问题似乎是运行iOS 4.3.2的iOS模拟器中的一个bug


如果您发现了这个问题,请将您的部署目标设置为较旧的SDK,例如4.2,并在其上运行您的应用程序。

您是否调用了[tableView reloadData];删除后,我尝试了它。动画无法工作,行仍然可见。请检查TabeView的editingStyle是否为UITableViewCellEditingStyleDelete我在iPhone上没有问题,但在模拟器上没有问题。。!有虫子吗?!在模拟器上,没有表视图编辑对我有效