我在 Interface Builder 中创建了一个 UITableViewCell,我添加了一个 UIImageView 和一个 UIButton。我为 UIButton 提供了一个插座,并将其连接到 IBAction 并设置了 touch up inside 事件集。我以为它会调用这个方法,因为一切看起来都像是连接起来的:
- (IBAction)pressedCheckbox:(id)sender {
[sender setBackgroundImage:[UIImage imageNamed:@"checked.png"] forState:UIControlStateNormal];
NSLog(@"clicked check");
}
检查连接选项卡,我已正确设置所有内容,插座和操作。而且我没有收到任何错误,但是在预览应用程序时,单击 UITableViewCell 内的该按钮什么也不做,而且我在日志中看不到任何内容。
关于为什么它不允许我单击 UITableViewCell 中的按钮的想法?
编辑:
cellForRowAtIndexPath 的代码:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
cell.editingAccessoryType = UITableViewCellAccessoryDisclosureIndicator;
cell.selectionStyle = UITableViewCellSelectionStyleNone;
}
if (indexPath.section == 0) {
switch (indexPath.row) {
case 0:
cell = topCell;
break;
case 1:
cell = cell1;
break;
}//end switch
}//end if
return cell;
}