首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >UITableView编辑不起作用

UITableView编辑不起作用
EN

Stack Overflow用户
提问于 2011-05-26 12:08:43
回答 2查看 2.6K关注 0票数 2

我有一个UITableView,它位于一个弹出窗口中的NavigationController中。因此,我放置了一个编辑/完成UIToolBarItem,它工作得很好,您可以看到删除附件图标出现。但是,当我重新排列项目时,编辑/完成按钮停止工作...

我调试过了,它仍然被调用,但它似乎没有更新,并且在某种程度上阻止了来自其他按钮的任何进一步更新。这可能是模拟器的问题吗?

提前感谢您的帮助!

编辑:添加代码

代码语言:javascript
复制
addButton = [[UIBarButtonItem alloc] initWithTitle:@"Edit" style:UIBarButtonItemStyleBordered     target:self action:@selector(editTable:)];

在后面的方法中:

代码语言:javascript
复制
- (IBAction) editTable: (id) sender
{
    if ([[addButton title] isEqualToString:EDIT_STRING]) {
        [addButton setTitle:DONE_STRING]; //enabling edit mode  
        [super setEditing:YES animated:YES];
        [[self tableView] setEditing:YES animated:YES];
    }
    else {
        [addButton setTitle:EDIT_STRING]; //done with editing
        [[self tableView] setEditing:NO animated:YES];
        [super setEditing:NO animated:YES];

        [[self tableView] setNeedsDisplay];
        [[self tableView] reloadData];  
    }
}

第二部分肯定会被调用,因为addButton文本正在发生变化。但是,一旦我进行了编辑(例如重新排列行),它就会停止工作

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2011-05-27 09:53:46

好的,

我似乎调用了tableView beginUpdates,但从未调用过endUpdates,这导致所有更新都无法注册。如果其他人这么做的话。

票数 3
EN

Stack Overflow用户

发布于 2011-05-27 11:44:54

代码语言:javascript
复制
- (void)tableView:(UITableView *)tableview commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
    if (editingStyle == UITableViewCellEditingStyleDelete) {
        [self.tv deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
        [self.tv reloadData];
    }
}

- (void)setEditing:(BOOL)editing animated:(BOOL)animated {
    [super setEditing:editing animated:animated];
    [self.tv setEditing:editing animated:YES];
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/6133557

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档