4

我需要在目标 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
    }
}

如果我需要澄清任何事情,请告诉我。谢谢。

在此处输入图像描述

4

1 回答 1

0

看看这个答案iPhone UITableView - Delete Button,它应该基本上回答了你的问题。简而言之,您可能需要继承UITableViewCell并覆盖-(void)willTransitionToState:(UITableViewCellStateMask)state-(void)didTransitionToState:(UITableViewCellStateMask)state并在此处修改按钮。

另一种选择可能是子类化UITableViewCell并自己实现删除按钮功能(识别滑动手势,在按下按钮时呈现按钮和句柄,类似于UITableView委托的默认方法)。

于 2012-06-27T13:05:19.703 回答