1

Say, for example, I was wanting to edit the title for the highlighted state, is this possible?

I know it is possible with custom UIButtons, but is it possible to edit the properties of the UITableViewCellAccessoryDetailDisclosureButton?

If not, is it possible to create a custom button and still call a UITableView delegate method? If so, how would one pass the indexPath from a custom button cell?

Cheers!

rptwsthi
  • 10,094
  • 10
  • 68
  • 109
Sebastien Peek
  • 2,528
  • 2
  • 23
  • 32

3 Answers3

1

give your custom button.tag=indexPath.row and access row no. from button tag

ex:-

    UIButton *deleteButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [deleteButton setFrame:CGRectMake(285, 5, 30, 30)];
    deleteButton.contentMode = UIViewContentModeScaleAspectFill;     
    UIImage *newImage12 = [UIImage imageNamed:@"x.png"];
    deleteButton.tag = indexPath.row;
    [deleteButton setBackgroundImage:newImage12 forState:UIControlStateNormal];
    [deleteButton setBackgroundImage:newImage12 forState:UIControlStateHighlighted];
    [deleteButton addTarget:self action:@selector(deleteRemindersMethod:) forControlEvents:UIControlEventTouchUpInside];
    [cell.contentView addSubview:deleteButton];

-(void)deleteRemindersMethod:(UIButton *)sender
{
    int rowNO=sender.tag;
}
Gypsa
  • 11,230
  • 6
  • 44
  • 82
1

To the best of my knowledge, you'll have to set your own button as the accessory view. There are several ways to get the indexPath and my preferred is to get the touch coordinates using locationInView: and then indexPathForRowAtPoint: to get the actual indexPath that you need:

CGPoint location = [sender locationInView:self.tableView];
NSIndexPath *indexPath = [self.tableView indexPathForRowAtPoint:location];
UITableViewCell *cell = [self.tableView cellForRowAtIndexPath:indexPath];

(code taken from here)

Community
  • 1
  • 1
phi
  • 10,634
  • 6
  • 53
  • 88
1

You can create a custom UIButton and assign it to the accessoryView property of your cell. If you want to do sth. really custom for the highlighted state of cells you should consider subclassing UITableViewCell and override setSelected:animated:

Martin Ullrich
  • 94,744
  • 25
  • 252
  • 217