如何在objective-CIOS5中设置默认删除按钮的样式?

如何在objective-CIOS5中设置默认删除按钮的样式?,objective-c,ios5,Objective C,Ios5,我需要在objective c,ios5中的tableview单元格上设置默认删除按钮的样式。总的想法是假设您可以这样做: UIImage *addImage = [UIImage imageNamed:@"greenButtonDark.png"]; UIButton *addButton = [UIButton buttonWithType:UIButtonTypeCustom]; addButton.frame = CGRectMake(0, 0, addImage

我需要在objective c,ios5中的tableview单元格上设置默认删除按钮的样式。总的想法是假设您可以这样做:

    UIImage *addImage = [UIImage imageNamed:@"greenButtonDark.png"];
    UIButton *addButton = [UIButton buttonWithType:UIButtonTypeCustom];
    addButton.frame = CGRectMake(0, 0, addImage.size.width, addImage.size.height);

    [addButton setImage:addImage forState:UIControlStateNormal];
    [addButton addTarget:self action:@selector(pushAddItem) forControlEvents:UIControlEventTouchUpInside];

    UIBarButtonItem *addBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:addButton] ;

    self.navigationItem.rightBarButtonItem = addBarButtonItem;
上述代码在viewDidLoad方法中调用,并覆盖标题中的右按钮。我假设系统默认添加的任何按钮都有可比性,但我不知道如何访问这个特定的按钮

如果我无法清楚地表达这一点,我提到的删除按钮就是用此代码自动生成的按钮

- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
    if(editingStyle == UITableViewCellEditingStyleDelete)
    {
        //do something when someone hits delete
    }
}
如果我需要澄清任何事情,请告诉我。谢谢


看看这个答案,它应该基本上回答了你的问题。简而言之,您可能需要为UITableViewCell创建子类,并覆盖-voidWillTransitionOnState:UITableViewCellStateMasksState和-voidDidTransitionOnState:UITableViewCellStateMasksState并修改此处的按钮


另一种选择可能是对UITableView单元格进行子类化,并自行实现删除按钮功能。以与UITableView委托的默认方法类似的方式,识别滑动手势,在按下时显示按钮和手柄。

您是否尝试过对UITableView进行子类化?这可能有用。您必须发现哪些方法调用了-tableView:committeeditingstyle:forRowAtIndexPath:无论如何,为什么要删除防弹背心?不,我没有。人们可以以类似的方式访问默认按钮,这似乎是合乎逻辑的。无论如何,我希望你删除防弹背心,因为它表明你已经获得了它,不再需要它在你的名单上。你不能访问该按钮,除非更改标题。您可以使用自己的编辑附件视图来编辑单元格,但您还需要做一些额外的工作,以使编辑模式成为删除模式,并实现滑动删除等。有关此操作的一些链接,请参阅