How to disable the delete button for the particular row when we are using the table view delegate method commitEditingStyle in Iphone sdk?
Here I need a help from ur side that Im using the tableview delegate method commitEditing sytle to get the delete button for every cell when we swipe.But my problem 开发者_如何学JAVAhere is I dont want the delete button for the first row in the tableview and swipe should not work and I dnt have any idea how to implemet this.
Anyone's help will be much appreciated.
Thank You,
Monish.
UITableViewCell
has delete style by default. To change that you need to implement tableView:editingStyleForRowAtIndexPath:
method in your table view delegate. Return UITableViewCellEditingStyleNone
for the 1st row and UITableViewCellEditingStyleDelete
for other rows.
Edit: Sorry for incomplete answer. You also need to implement tableView:canEditRowAtIndexPath:
method (something like that):
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath{
return indexPath.row > 0;
}
Hope that'll work
- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath
{
if(condition check)
return UITableViewCellEditingStyleDelete;
return UITableViewCellEditingStyleNone;
}
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
if (editingStyle == UITableViewCellEditingStyleDelete) {
//here your code
}
}
精彩评论