Reputation: 12431
Can anyone advise me on how I can add a "plus" button in a UITableView Cell like what you see in the screen shot below?
Upvotes: 7
Views: 8241
Reputation:
You can also put the table view into editing mode, implement editingStyleForRowAtIndexPath:
and return UITableViewCellEditingStyleInsert
(which puts a green circle with a plus sign).
For example...
- (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...
}
}
Upvotes: 31
Reputation: 4248
The simple way: get an image of the plus, set it for the cell.imageView.image
.
Upvotes: 1
Reputation: 19867
You can customize your cell by getting the contentView
property of your UITableViewCell
and adding the UIImage
of the plus button as a subview.
Upvotes: 0
Reputation: 21903
That's not a built-in control. It's probably a custom-style UIButton with that image in its .image property.
Upvotes: -1