设置配件按钮框架

时间:2013-02-08 11:11:35

标签: iphone ios

在我的iPhone应用程序中,我在每个单元格中添加了一个附件按钮。

以下是我的代码:

    ContactCell *contactCell = (ContactCell *)[tableView dequeueReusableCellWithIdentifier:kCellID];
    if (contactCell == nil) {
        contactCell = [[ContactCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:kCellID];
        contactCell.frame = CGRectMake(0.0, 0.0, 320.0, ROW_HEIGHT);
    }

    UIImage *callButtonImage=[UIImage imageNamed:@"call-person.png"];
    UIButton *button =[UIButton buttonWithType:UIButtonTypeCustom];
    button.frame=CGRectMake(0.0, 0.0, 200, ROW_HEIGHT);
    [button setBackgroundImage:callButtonImage forState:UIControlStateNormal];

    ContactWrapper *cellWrapper = nil;  
            [button addTarget:self action:@selector(askCallForClientContact:) forControlEvents:UIControlEventTouchUpInside];
            contactCell.accessoryView = button;

我将按钮框设置为:button.frame=CGRectMake(0.0, 0.0, 200, ROW_HEIGHT);

但似乎按钮框架的数量少于200.当我点击一个单元格并假设有一个按钮时,会出现didSelectRowAtIndexPath个事件,而不是askCallForClientContact:个事件。如何设置配件按钮的框架?我需要200宽度?

1 个答案:

答案 0 :(得分:0)

不,你不能改变accessoryView的框架。作为替代方案,您可以向细胞添加子视图

[cell.contentView addSubview:aView];