UITableView 在编辑模式下将单元格添加到底部

发布于 2024-12-29 05:49:44 字数 128 浏览 4 评论 0原文

我试图让我的表格在表格底部添加一个单元格以添加单元格,我的表格处于删除模式,因此人们可以删除,但随后我需要它添加一个带有插入功能的单元格,该单元格将插入一个单元格。我收到错误消息说我的应用程序与 nsarray 不一致。我怎样才能做到这一点?

I'm trying to make my table add a cell at the bottom of the table for adding cells, my table is on delete mode, so people can delete, but then then i need it to add a cell with insert that will insert a cell. i get errors saying my app isn't consistent with the nsarray. how could i make this work?

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

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

发布评论

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

评论(1

夜灵血窟げ 2025-01-05 05:49:44

第 1 步覆盖 tableViewController 上的 setEditing 以插入或删除添加行

- (void)setEditing:(BOOL)editing animated:(BOOL)animate
{
    BOOL prevEditing = self.editing;

    [super setEditing:editing animated:animate];
    [tableView setEditing:editing animated:animate];
    if (editing && !prevEditing) {
        // started editing
        [self.tableView insertRowsAtIndexPaths:....] withRowAnimation:UITableViewRowAnimationFade];
    } else if (!editing && prevEditing) {
        // stopped editing
        [self.tableView deleteRowsAtIndexPaths:....] withRowAnimation:UITableViewRowAnimationFade];

    }


}

然后确保返回正确的行数

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    NSInteger numberOfRows = xxxxxx;

    if (self.editing) {
        numberOfRows++;
    }
    return numberOfRows;
}

Step 1 override setEditing on your tableViewController to insert or delete the add row

- (void)setEditing:(BOOL)editing animated:(BOOL)animate
{
    BOOL prevEditing = self.editing;

    [super setEditing:editing animated:animate];
    [tableView setEditing:editing animated:animate];
    if (editing && !prevEditing) {
        // started editing
        [self.tableView insertRowsAtIndexPaths:....] withRowAnimation:UITableViewRowAnimationFade];
    } else if (!editing && prevEditing) {
        // stopped editing
        [self.tableView deleteRowsAtIndexPaths:....] withRowAnimation:UITableViewRowAnimationFade];

    }


}

Then ensure you are returning the right number of rows

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    NSInteger numberOfRows = xxxxxx;

    if (self.editing) {
        numberOfRows++;
    }
    return numberOfRows;
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文