开发者

Unable to swipe delete first row of table in iPhone app

I have an iPhone app that utilizes TableView to list tagged items that the user has saved. I have Swipe to Delete enabled for these items yet I'm running into an issue with the very first item in the table. All other items show the "Delete" button when swiped, but it does not work for the very first row.

I've searched and searched for an answer to this. I'd appreciate the help!

- (UITableViewCellEditingStyle) tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath {
    if([indexPath row] == 0) {
        return UITableViewCellEditingStyle开发者_运维问答None;
    }

    return UITableViewCellEditingStyleDelete;
}


You should return UITableViewCellEditingStyleDelete from tableView:editingStyleForRowAtIndexPath: for all rows that should support delete.

UPDATE
I have explained what your code does in some added comments, so you can see the problem:

- (UITableViewCellEditingStyle) tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath {
    if([indexPath row] == 0) {
        // any row that returns UITableViewCellEditingStyleNone will NOT support delete (in your case, the first row is returning this)
        return UITableViewCellEditingStyleNone;
    }

    // any row that returns UITableViewCellEditingStyleDelete will support delete (in your case, all but the first row is returning this)
    return UITableViewCellEditingStyleDelete;
}
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜