Ios 自定义UITableViewCell accessoryView按钮在实际设备上不可见
在我的Ios 自定义UITableViewCell accessoryView按钮在实际设备上不可见,ios,uitableview,uibutton,Ios,Uitableview,Uibutton,在我的UITableView中,我想为表中的行添加customaccessoryview按钮;这是添加到UITableViewCellcellforrowatinexpath方法中的代码: UIImage *image = [UIImage imageNamed:@"icon.png"]; UIButton *button = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 28, 28)]; // tested also ini
UITableView
中,我想为表中的行添加customaccessoryview
按钮;这是添加到UITableViewCell
cellforrowatinexpath方法中的代码:
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事件。但如果我在真正的设备上测试我的应用程序(iPhone4和iOS 5.1或iPad3rd和iOS 6.1),我看不到自定义按钮,它是不可见的,事实上,点击每行的右侧仍会调用accessoryButtonTapped事件。我也删除并重新安装了应用程序,我能做什么?如果调用了您的方法,则表示按钮在那里。问题在于你的形象。在设备上运行时,检查映像是否为零,以及映像是否已添加到构建目标。哦,难以置信!我选择了唯一没有添加到构建目标的图像!出于某种奇怪的原因,“icon.png”不在应用程序文件夹中!非常感谢。