私の場合、テーブルの行にボタンUITableView
を追加したいと思います。これは、 cellForRowAtIndexPathメソッドcustom accessoryView
に追加されたコードです。UITableViewCell
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シミュレーター(iOS5.1およびiOS6.1)で完全に機能し、テーブルの各行の右側にicon.png画像を含むカスタムUIButtonを確認できます。また、カスタム画像をタップしてaccessoryButtonTappedイベントを呼び出すこともできます。しかし、REALデバイス(iOS5.1のiPhone4またはiOS6.1のiPad3rd)でアプリをテストすると、カスタムボタンが表示されません。実際、各行の右側をタップすると、accessoryButtonTappedイベントが呼び出されます。アプリも削除して再インストールしましたが、どうすればよいですか?