如何在编辑模式下在 UITableViewCell 中设置自定义编辑样式图标

发布于 2024-08-18 12:18:59 字数 128 浏览 13 评论 0原文

在 UITableView 中启用编辑模式时,有没有办法拥有自定义编辑样式图标(除了绿色加号和红色减号图标之外)?

我知道我可以模拟编辑模式动画,只需将单元格内容移动到右侧并添加 UIImageView,但我试图避免这种情况。

Is there any way to have a custom edit-style icon (besides the green plus and red minus icons) when enabling edit-mode in a UITableView?

I know I could simulate the the edit-mode animation and just move the cell contents to the right and add a UIImageView, but I was trying to avoid that.

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

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

发布评论

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

评论(2

梦幻的味道 2024-08-25 12:18:59

自定义单元格编辑样式的唯一方法是使用 tableView:editingStyleForRowAtIndexPath: ,它必须返回 UITableViewCellEditingStyle。

无、删除(红色减号)和插入(绿色加号)是唯一的选项。来自 文档

单元格编辑样式

编辑控件
由细胞使用。

typedef 枚举 {   
UITableViewCellEditingStyleNone,   
UITableViewCellEditingStyleDelete,   
UITableViewCellEditingStyleInsert  
UITableViewCellEditingStyle;

The only way to customize the editing style of a cell is using tableView:editingStyleForRowAtIndexPath: which must return a UITableViewCellEditingStyle.

None, delete (red minus), and insert (green plus) are the only options. From the documentation:

Cell Editing Style

The editing control
used by a cell.

typedef enum {   
UITableViewCellEditingStyleNone,   
UITableViewCellEditingStyleDelete,   
UITableViewCellEditingStyleInsert  
} UITableViewCellEditingStyle;
无悔心 2024-08-25 12:18:59

可以按照下面的代码返回

-(UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath
{  
if(indexPath.row == 0) 
    {

        return  UITableViewCellEditingStyleInsert;
    }
    else
    {
        return UITableViewCellEditingStyleDelete;
    }
}

You can return as shown in below code

-(UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath
{  
if(indexPath.row == 0) 
    {

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