IOS UITableView 可移动行实例

来源:互联网 发布:淘宝购物车设计 编辑:程序博客网 时间:2024/05/21 15:00

作者:朱克锋

邮箱:zhukefeng@iboxpay.com

转载请注明出处:http://blog.csdn.net/linux_zkf

效果图如下所示:(注意Toe这一行变化)


移动前                                                                           移动后

IOS UITableView 可移动行主要还是代理方法的实现,下面给出主要的代码,其它代码均未给出,都是一些很通用的代码。

IOS UITableView 可删除行类似,首先要调用下面这行代码

 [self.tableViewsetEditing:YES animated:YES];

或者实现其代理方法也是一样的

- (void)setEditing:(BOOL)editing animated:(BOOL)animated

{

[super setEditing:editinganimated:animated];

[self.tableViewsetEditing:editing animated:animated];

}


这里是代理方法的实现:

- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView

           editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath {

    returnUITableViewCellEditingStyleNone;

}

- (BOOL)tableView:(UITableView *)tableView

canMoveRowAtIndexPath:(NSIndexPath *)indexPath {

    return YES;

}

- (void)tableView:(UITableView *)tableView

moveRowAtIndexPath:(NSIndexPath *)fromIndexPath

  toIndexPath:(NSIndexPath *)toIndexPath {

    NSUInteger fromRow = [fromIndexPath row];

    NSUInteger toRow = [toIndexPath row];

    id object = [[listobjectAtIndex:fromRow] retain];

    [listremoveObjectAtIndex:fromRow];

    [list insertObject:objectatIndex:toRow];

    [object release];

}

其中list为:

 NSMutableArray *list;