编辑模式删除特定 TableView 行的微调器图标

发布于 2024-09-01 08:02:27 字数 377 浏览 15 评论 0原文

我有一个分组的表格视图。每个部分有三行。我需要能够一次删除一个部分。使用标准编辑模式,我可以让它工作。但是,删除图标显示在每个单元格的左侧,而不仅仅是每个部分的第一行。

有没有办法抑制除第一行之外的所有行的小微调器图标?

我希望有一种简单的方法可以做到这一点而无需子类化。

以下屏幕截图可帮助您直观地看到它:http://picasaweb.google .com/lh/photo/ll-EJY5ACw7oqHH1xKBQ8w?feat=directlink

I have a grouped tableview. Each section has three rows. I need to be able to delete one section at a time. Using the standard edit mode, I can make it work. However, the delete icon shows up to the left of each cell, not just the first row in each section.

Is there a way to suppress the little spinner icon for all rows except the first?

I am hoping there is an easy way to do this without subclassing.

Here is a screenshot to help visualize it: http://picasaweb.google.com/lh/photo/ll-EJY5ACw7oqHH1xKBQ8w?feat=directlink

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

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

发布评论

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

评论(2

雨后彩虹 2024-09-08 08:02:27

试试这个:

- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath {
    if(indexPath.row == 0) {
        return UITableViewCellEditingStyleDelete;
    } else {
        return UITableViewCellEditingStyleNone;
    }
}

Try this:

- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath {
    if(indexPath.row == 0) {
        return UITableViewCellEditingStyleDelete;
    } else {
        return UITableViewCellEditingStyleNone;
    }
}

不要删除行,而是创建一个包含 UILabel 和自定义 UIButton 作为子视图的父 UIView。将此父视图设置为 节标题视图

应连接按钮以触发删除行的方法,例如,翻转该部分的 BOOL 状态标志,然后重新加载表:

- (void) deleteMySection:(id)sender {
    self.showMySection = NO;
    [tableView reloadData];
}

您的 -numberOfSectionsInTableView: 委托方法将根据此布尔标志的状态相应地调整其输出,例如

- (NSInteger) numberOfSectionsInTableView:(UITableView *)tv {
    return ((showMySection) ? numberOfSections : numberOfSections - 1);
}

Instead of deleting rows, make a parent UIView that contains a UILabel and custom UIButton as subviews. Set this parent view as the section header view.

The button should be wired up to trigger a method that deletes rows by, for example, flipping a BOOL state flag for that section and then reloading the table:

- (void) deleteMySection:(id)sender {
    self.showMySection = NO;
    [tableView reloadData];
}

Your -numberOfSectionsInTableView: delegate method will accordingly adjust its output depending on the state of this boolean flag, e.g.

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