UITableView 编辑不起作用

发布于 2024-11-09 15:28:11 字数 1040 浏览 0 评论 0原文

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

我进行了调试,它仍然被调用,但它似乎没有更新,并且有点阻止其他按钮的任何进一步更新。这可能是模拟器的问题吗?

感谢您提前的帮助!

编辑:添加代码

addButton = [[UIBarButtonItem alloc] initWithTitle:@"Edit" style:UIBarButtonItemStyleBordered     target:self action:@selector(editTable:)];

稍后介绍方法:

- (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 文本的更改,第二部分肯定会被调用。但是,一旦我进行编辑(例如重新排列行),它就会停止工作

I have a UITableView which lies in a NavigationController that is in a popover. So, I put an edit/done UIToolBarItem which works fine and you can see the delete accessory icon showing up. However, when I rearrange the items, the edit/done button stops working...

I debugged and it still gets called but it doesn't seem to update and is sort of preventing any further updates from other buttons. Is this possibly a problem with the simulator?

Thanks for the help in advance!

Edit: Adding code

addButton = [[UIBarButtonItem alloc] initWithTitle:@"Edit" style:UIBarButtonItemStyleBordered     target:self action:@selector(editTable:)];

And later on the method:

- (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];  
    }
}

The second part is definitely called as the addButton text is changing. However, it stops working once I make an edit (such as re-arranging a row)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

淤浪 2024-11-16 15:28:11

好吧,

我似乎已经调用了 [tableView beginUpdates] 而从未调用过 endUpdates,这导致所有更新都未注册。如果其他人这样做的话...

Alright,

I seemed to have called [tableView beginUpdates] and never called endUpdates, which was causing all updates to not be registered. If anyone else does that...

后来的我们 2024-11-16 15:28:11
- (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];
}
- (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];
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文