Objective:
- Add a custom button as titled
Delete
in a row whenever it selected And remove it whenever cell selection changes and so on add 'Delete' to last selection.
(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath*)indexPath{ self.myIndexPath=indexPath; UIButton *btnCustomDelete=[[UIButton alloc] initWithFrame:CGRectMake(260, 10, 60, 7)]; [btnCustomDelete setTitle:@"Delete" forState:UIControlStateNormal]; [tblCellForContactTable.contentView addSubview: btnCustomDelete]; //I think correction wants here [btnCustomDelete addTarget:self action:@selector(actionCustomDelete:) forControlEvents:UIControlEventTouchUpInside]; } -(IBAction) actionCustomDelete:(id)sender{ [arrForMyContacts removeObject:[arrForMyContacts objectAtIndex:myIndexPath.row]]; [tblForContacts reloadData]; }
But, its not worked all time.