SILminore
SILminore

Reputation: 509

Custom UITableViewCell accessoryView button invisible on REAL device

In my UITableView I want to add custom accessoryView button for the rows in the table; this is the code, added in the UITableViewCell cellForRowAtIndexPath method:

    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];

This perfectly works on the iOS simulator (iOS 5.1 and iOS 6.1), I can see the custom UIButton with icon.png image on the right of each row of the table and I can also call the accessoryButtonTapped event tapping on the custom image. But if I test my app on REAL device (iPhone 4 with iOS 5.1 or iPad 3rd with iOS 6.1) I cannot see the custom button, it is invisible, in fact tapping on the right of each rows still calls the accessoryButtonTapped event. I have deleted and re-installed app too, what can I do?

Upvotes: 0

Views: 2342

Answers (1)

devluv
devluv

Reputation: 2017

if your method is getting called, it means the button is there. the problem is with your image. While running on device, check if the image is nil or not, and whether the image has been added to the build target.

Upvotes: 2

Related Questions