Add the Plus Button for AccessoryType TableView

I am trying to implement a TableView where each cell has a + button just like an iPod application when adding songs to a playlist.

cell.accesoryType has only four values

 UITableViewCellAccessoryCheckmark UITableViewCellAccessoryDetailDisclosureButton 

UITableViewCellAccessoryDisclosureIndicator

and

 None 

How can I do that? Do I need to create a custom button and set cell.accessoryView or is there another way to do this?

+6
source share
4 answers

Teo's solution works fine, but it has not been posted as an answer, so I will reprogram it:

 UIButton *button = [UIButton buttonWithType:UIButtonTypeContactAdd]; [button addTarget:self action:@selector(addbuttonTapped) forControlEvents:UIControlEventTouchUpInside]; cell.accessoryView = button; 
+12
source

A simple JosephH option for memory.

If you just want to create a decorative β€œ+” button and continue using the original didSelectRowAtIndexPath trigger, use:

 UIButton *button = [UIButton buttonWithType:UIButtonTypeContactAdd]; [button setUserInteractionEnabled:NO]; cell.accessoryView = button; 

By disabling the user’s interaction with the button, it will propagate the pressure event on the basic view: cell.

+3
source

If you create a custom cell , put a button in it in the right corner, as shown in the accessory type , and assign its β€œ+” image to the button so that you also β€œsee” the image and receive a β€œbutton action event”.

Refer this tutorial for custom uitableviewcells.

0
source
0
source

Source: https://habr.com/ru/post/890277/


All Articles