如何在编辑模式下在UITableView中添加额外的单元格? [英] How to add extra cells in a UITableView in editing mode?

查看:87
本文介绍了如何在编辑模式下在UITableView中添加额外的单元格?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在表格进入编辑模式后,您知道如何让一些单元格出现在表格视图中吗?就像在编辑联系人时iPhone应用程序执行的联系人。



也许我错了,但编辑联系人时,看起来像一个分组的UITableView 。



我尝试过:

  [self.tableView setEditing: YES animated:YES]; 
[self.tableView insertSections:[NSIndexSet indexSetWithIndex:1] withRowAnimation:UITableViewRowAnimationBottom];

我的表在不编辑时只有一个部分,我想在编辑时添加一个部分保持它的简单),但是调用'insertSections'上面崩溃(所有我的表委托考虑到1或2部分,取决于self.editing,我试图显示两个部分在正常模式,它工作正常) / p>

对于'numberOfSectionsInTableView'我有:

   - (NSInteger)numberOfSectionsInTableView :(UITableView *)tableView {
if(!self.editing)return 1;
return 2;
}


解决方案

状态的tableView?你应该在 - [UINavigationController setEditing:animated:]中执行它:

   - (void)setEditing: (BOOL)animated {
[super setEditing:editing animated:animated];
[self.tableView setEditing:editing animated:animated];

if(编辑){
[self.tableView insertSections:[NSIndexSet indexSetWithIndex:1] withRowAnimation:UITableViewRowAnimationBottom];
} else {
// delete section
}
}


$ b b

因此,不是在tableView上调用setEditing,而是在navigationController(可能 self )上调用它。然后控制器将处理编辑模式。



所以控制器有一个编辑模式,tableView有。以编程方式设置tableView后,或者当用户滑动以删除行时,tableView将处于编辑模式。在后一种情况下,在编辑模式下,但 tableView


Do you know how to have some cells appear in a table view after the table goes into editing mode? Just like the "Contacts" iPhone app does when you edit a contact.

Maybe I'm wrong, but when editing the contacts, it looks like a grouped UITableView is used.

I tried this:

[self.tableView setEditing:YES animated:YES];
[self.tableView insertSections:[NSIndexSet indexSetWithIndex:1] withRowAnimation:UITableViewRowAnimationBottom];

My table has only 1 section when not editing it, I wanted to add an extra section when editing (to keep it simple), but the call to 'insertSections' above crashes (all my table delegates take into account the 1 or 2 sections well depending on self.editing, I tried showing both sections in normal mode, and it works fine)

For 'numberOfSectionsInTableView' I have:

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    if (!self.editing) return 1;
    return 2;
}

解决方案

Where did you enter the editing state of the tableView? You should do it in -[UINavigationController setEditing:animated:]:

- (void)setEditing:(BOOL)editing animated:(BOOL)animated {
    [super setEditing:editing animated:animated];
    [self.tableView setEditing:editing animated:animated];

    if(editing){
        [self.tableView insertSections:[NSIndexSet indexSetWithIndex:1] withRowAnimation:UITableViewRowAnimationBottom];
    } else {
        // delete section
    }
}

So instead of calling setEditing on the tableView, call it on the navigationController (probably self) The controller will then handle the editing mode.

So the controller has an editing mode, and the tableView has. The tableView will be in editing mode once you set it programmatically, or when the user swipes to delete a row. In the latter case, the controller is not in editing mode, but the tableView is.

这篇关于如何在编辑模式下在UITableView中添加额外的单元格?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆