开发者

UITableViewCellEditingStyle both Insert and Delete at the same time

the book I'm studying to program for iPhone says I can have a mixture of both UITableViewCellEditingStyle-Insert/Delete at the same time. But I couldn't figure out how to do it.There's a UITableViewdataSource 开发者_Go百科method return type of which is UITableViewCellEditingStyle.But how do I return both style simultanously if I can return just one thing-either insert or delete.


If I'm understanding correctly, you want to update your tableview by both deleting and adding a new cell (and optionally animating that change).You need to nest your calls inside a beginUpdates block:

[tableView beginUpdates]
[tableView deleteRowsAtIndexPaths...
[tableView insertRowsAtIndexPaths...
[tableView commitUpdates]

You need to make sure that your UITableViewDataSourceDelegate methods reflect that change when commitUpdates: gets called.


UITableViewCellEditingStyle is a enum, so I don't think it can insert and delete at the same time. Here is an answer that might help you:

-(UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.row == 0) {
        return UITableViewCellEditingStyleInsert;
    }
    else
    {
        return UITableViewCellEditingStyleDelete;
    }
}
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜