Goal C: Add a Plus Button to a Cell

Can someone advise me how I can add a plus button in a UITableView cell, like what you see in the screenshot below?

enter image description here

+6
source share
4 answers

Easy way: get the plus image, set it to cell.imageView.image .

+1
source

You can also put the table view in edit mode, implement editingStyleForRowAtIndexPath: and return UITableViewCellEditingStyleInsert (which puts a green circle with a plus sign).

For instance...

 - (IBAction)editButtonPressed { //toggle editing on/off... [tableView setEditing:(!tableView.editing) animated:YES]; } - (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath { if (indexPath.row == 0) return UITableViewCellEditingStyleInsert; //gives green circle with + else return UITableViewCellEditingStyleDelete; //or UITableViewCellEditingStyleNone } 

When the green button is pressed, the table view will call tableView:commitEditingStyle:forRowAtIndexPath: ::

 - (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath { if (editingStyle == UITableViewCellEditingStyleInsert) { //handle insert... } else { //handle delete... } } 
+26
source

You can customize your cell by getting the contentView property of your UITableViewCell and adding the UIImage plus buttons as a subtitle.

0
source

This is not an inline control. This is probably a regular-style UIButton with this image in its .image property.

-1
source

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


All Articles