Reputation: 269
i'm trying to implement a TableView where each cell has a '+
' button just like the iPod app when adding songs to a playlist.
The cell.accesoryType
has only four values
UITableViewCellAccessoryCheckmark
UITableViewCellAccessoryDetailDisclosureButton
UITableViewCellAccessoryDisclosureIndicator
and
None
How can this be done? Do i need to create a custom button and set the cell.accessoryView
or is there another way to do this?
Upvotes: 7
Views: 7502
Reputation:
A simple variant of JosephH, for memory.
If you simply want a decorative "+" button and continue using the original didSelectRowAtIndexPath trigger, use :
UIButton *button = [UIButton buttonWithType:UIButtonTypeContactAdd];
[button setUserInteractionEnabled:NO];
cell.accessoryView = button;
By disabling user interaction on the button, it will propagate pressure event on the underlying view : the cell.
Upvotes: 3
Reputation: 37505
Teo's solution works great, but it's not been posted as an answer, so I'm reposting it:
UIButton *button = [UIButton buttonWithType:UIButtonTypeContactAdd];
[button addTarget:self action:@selector(addbuttonTapped) forControlEvents:UIControlEventTouchUpInside];
cell.accessoryView = button;
Upvotes: 13
Reputation: 10864
You may take a look to setEditing:animated:
Check also Setting the editing style on a UITableViewCell
Upvotes: 0
Reputation:
If you are creating a custom cell
, then place a button
on it at the right corner, just like where accessory type
appears and assign it your '+' image to the button, so that you also "see the image" and get the "button action event".
Refer this tutorial for custom uitableviewcells.
Upvotes: 0