开发者

not able to see Delete button when swpping UITableViewCell

开发者 https://www.devze.com 2023-03-15 08:59 出处:网络
I am trying to delete UITableViewCell from UITableView. Implemented UITableViewDelegate, UITableViewDataSource to my UIViewController.

I am trying to delete UITableViewCell from UITableView.

Implemented UITableViewDelegate, UITableViewDataSource to my UIViewController.

Also implement all m开发者_JAVA百科ethods which need to define for above delegates these are like,

- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath;
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath;

Set UITableView to editing mode also,

  [tableView setEditing:YES animated:YES];

When i click on Delete button to set tableView in Editing mode, i can see '-'sign red button but when i clicked that button not able to see "Delete" button, also not able to see when swipe on cell.

I go through all posts from stackoverflow, but can't get solution.

Thanks in advance.


I think you are missing the tableView:editingStyleForRowAtIndexPath method. Try to add the code below to your implementation.

- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath {
    return UITableViewCellEditingStyleDelete;
}


heres what i use to accomplish this:

- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath{
    [myArray removeObjectAtIndex:indexPath.row];
    [tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
}


please remove

[tableView setEditing:YES animated:YES];

and just use this method

- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
    // Return YES if you want the specified item to be editable.
    return YES;
}

and implement action on delete button - (void)tableView:(UITableView *)tableView commitEditingStyle:

(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
 //add action on delete button
}


This method is used to display the delete button while swiping the selected TableViewCell.

- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView 
       editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath {
}

This method will perform action on tapping the delete button while swiping the TableViewCell

- (void)tableView:(UITableView *)tableView 
        commitEditingStyle:(UITableViewCellEditingStyle)editingStyle
        forRowAtIndexPath:(NSIndexPath *)indexPath {
}

This method will update the tableview after deleting the row form the table view

- (void)tableView:(UITableView *)tableView 
                   didEndEditingRowAtIndexPath:(NSIndexPath *)indexPath {
}
0

精彩评论

暂无评论...
验证码 换一张
取 消