ios - UITableViewCell,显示没有滑动的滑动式删除按钮

标签 ios objective-c uitableview cocoa-touch delete-row

我搜索了几篇文章,但没有找到我要找的东西。基本上,我想在每一行上显示删除按钮,但我不想使用 UITableView.editing 属性。 因为它看起来像这样;

enter image description here

将有“编辑”按钮。当用户点击它时,删除按钮看起来像滑动式的。

是否有机会显示这样的删除按钮;

enter image description here

也许有一些方法可以解决它。否则,我将为此创建自定义 View 。

感谢您的建议。

- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
    // Return YES if you want the specified item to be editable.
    return YES;
}

- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
    if (editingStyle == UITableViewCellEditingStyleDelete) {

       //Do something... 
    }
}
- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView
           editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath {

    return UITableViewCellEditingStyleDelete;

}

最佳答案

  • 添加一个 bool 属性:@property BOOL didPressEdit;
  • UIButton 添加到UITableViewCell
  • 当按下编辑键时,didPressEdit 变为 TRUE 并且 UITableView 重新加载,这样 cell.deleteButton.hidden = !didPressEdit; 使所有删除按钮可用
  • 按下删除时,从数据源数组中删除对象,重新加载 TableView

希望对你有帮助

关于ios - UITableViewCell,显示没有滑动的滑动式删除按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33241836/

相关文章:

按钮上带有 PNG 的 iOS 抗锯齿

objective-c - 将 NSString 对象写入文件的典型方法是什么?

iphone - IB 自定义 UITableViewCell - 单元格和详细文本的动态高度

ios, swift : multiple tables, 单 View Controller

ios - ld : file too small for architecture i386

ios - UITableView 单元格模糊读取项目

ios - 如何将 Json 数据推送到 UITableView 中的标签?

objective-c - init方法中的(id)是什么意思?

iOS TabBarItem 两边小空间

ios - 使用 Storyboard和导航 Controller 检测 MPMoviePlayerController 上的点击