0

在我的 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宽吗?

4

1 回答 1

0

不,您不能更改附件视图的框架。作为替代方案,您可以将子视图添加到您的单元格

[cell.contentView addSubview:aView];
于 2013-02-08T11:18:29.603 回答