在我的UITableView
我想为custom accessoryView
表中的行添加按钮;这是在UITableViewCell
cellForRowAtIndexPath方法中添加的代码:
UIImage *image = [UIImage imageNamed:@"icon.png"];
UIButton *button = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 28, 28)]; // tested also initWithFrame:CGRectMake(0, 0, image.size.width, image.size.heigth)
[UIButton buttonWithType:UIButtonTypeCustom];
[button setBackgroundImage:image forState:UIControlStateNormal];
button.backgroundColor = [UIColor clearColor];
cell.accessoryView = button;
[button addTarget:self action:@selector(accessoryButtonTapped:event:) forControlEvents:UIControlEventTouchUpInside];
这在 iOS 模拟器(iOS 5.1 和 iOS 6.1)上完美运行,我可以在表格的每一行的右侧看到带有 icon.png 图像的自定义 UIButton,我还可以在自定义图像上调用accessoryButtonTapped 事件。但是,如果我在真实设备(带有 iOS 5.1 的 iPhone 4 或带有 iOS 6.1 的 iPad 3rd)上测试我的应用程序,我看不到自定义按钮,它是不可见的,实际上在每行右侧点击仍然会调用 accessoryButtonTapped 事件。我也删除并重新安装了应用程序,我该怎么办?