开发者

Preventing cell reordering for particular cells in iPhone SDK

I have 2 sections in my UITableView. I want the 2nd section to be movable but the 1st section of cells not. Specifying canEditRowAtIndexPath and canM开发者_JAVA技巧oveRowAtIndexPath doesn't help - the first section cells although not showing drag controls, they still change places if a cell from the 2nd section is dragged over. Is there a workaround for this?


Try implementing the targetIndexPathForMoveFromRowAtIndexPath method and forcing the row from the second section back to its original place if user tries to move it to the first section:

- (NSIndexPath *)tableView:(UITableView *)tableView targetIndexPathForMoveFromRowAtIndexPath:(NSIndexPath *)sourceIndexPath toProposedIndexPath:(NSIndexPath *)proposedDestinationIndexPath
{
    if (proposedDestinationIndexPath.section == 0)
    {
        return sourceIndexPath;
    }
    else 
    {
        return proposedDestinationIndexPath;
    }
}
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜