Reputation: 749
I added the edit button in the navigationbar. it works well and delete the cell. But , now i want to add the edit button to individaual cells to delete that cell only . what i mean that , if i have 5 cells enable in my tableview , i will add 5 edit buttons to them individaually.
Can u please anyone help me.
Thanks,
Chakradhar.
Upvotes: 0
Views: 1310
Reputation: 15639
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath*)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
UIButton *btn=[UIButton buttonWithType:UIButtonTypeCustom];
btn.tag = 194;
[btn setBackgroundColor:[UIColor clearColor]];
[btn setBackgroundImage:[UIImage imageNamed:@"edit_image.png"] forState:UIControlStateNormal];
[btn setFrame:CGRectMake(290, 15, 25, 25)];
[btn addTarget:self action:@selector(editTable:)
forControlEvents:UIControlEventTouchUpInside];
[cell.contentView addSubview:btn];
}
cell.textLabel.textColor = [UIColor whiteColor];
NSString *cellValue = [myArrayNew objectAtIndex:indexPath.row];
cell.textLabel.text = cellValue;
return cell; }
-(void) editTable:(id) sender {
UITableViewCell *clickedCell = (UITableViewCell *)[[sender superview] superview];
NSIndexPath *clickedButtonPath = [self.tableView indexPathForCell:clickedCell]; }
Try this code and reply me ......
Upvotes: 1
Reputation: 26400
You can probably use a custom cell with a button for the table view and have the button perform the desired action upon click events
Upvotes: 0