iphone - 在 UITableView 单元格中编辑时自定义删除按钮

标签 iphone uitableview

我已经浏览过this question显示以下代码:

-(NSString *)tableView:(UITableView *)tableView titleForDeleteConfirmationButtonForRowAtIndexPath:(NSIndexPath *)indexPath{
    return @"Sagar";
}

如果我想要自定义图像而不是默认的红色按钮怎么办?

最佳答案

在自定义单元格中实现此方法

- (void)willTransitionToState:(UITableViewCellStateMask)state{
    [super willTransitionToState:state];
    if ((state & UITableViewCellStateShowingDeleteConfirmationMask) == UITableViewCellStateShowingDeleteConfirmationMask) {
        for (UIView *subview in self.subviews) {
            if ([NSStringFromClass([subview class]) isEqualToString:@"UITableViewCellDeleteConfirmationControl"]) {
                UIImageView *deleteBtn = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 64, 33)];
                [deleteBtn setImage:[UIImage imageNamed:@"delete.png"]];
                [[subview.subviews objectAtIndex:0] addSubview:deleteBtn];
                [deleteBtn release];
            }
        }
    }
}

关于iphone - 在 UITableView 单元格中编辑时自定义删除按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1615469/

相关文章:

objective-c - 使用 NSFetchedResultsController 从 UITableView 中删除

ios - TableView (_ :heightForHeaderInSection:) not working

ios - 在 tableView 中使用按钮/图像 :editActionsForRowAt:

ios - 尝试加载 xib 文件时无法同时满足约束条件

ios - 如何在 Xcode 9 中在 iOS 设备上运行我的应用程序?

iphone - UIImageView 上的 UIButtons 缩放

ios - 超视觉 iPhone 应用程序,如 UIView 或 UITableView 滚动

android - 适用于 android 和 iphone 的 RabbitMQ 或 ActiveMQ

iphone - UIKeyboard 通知的最佳实践 - iPhone SDK

objective-c - UIWebView 作为 TableView 部分中页脚的 View 。奇怪的崩溃 - 附上崩溃日志