teo
teo

Reputation: 269

Add "Plus" button for AccessoryType TableView

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

Answers (4)

user3484366
user3484366

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

JosephH
JosephH

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

Manlio
Manlio

Reputation: 10864

You may take a look to setEditing:animated:
Check also Setting the editing style on a UITableViewCell

Upvotes: 0

user745098
user745098

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

Related Questions