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