作者:朱克锋
转载请注明出处:http://blog.csdn.net/linux_zkf
效果图如下所示:(注意Toe这一行变化)
移动前 移动后
IOS UITableView 可移动行主要还是代理方法的实现,下面给出主要的代码,其它代码均未给出,都是一些很通用的代码。
和IOS UITableView 可删除行类似,首先要调用下面这行代码
[self.tableView setEditing:YES animated:YES];
或者实现其代理方法也是一样的
- (void)setEditing:(BOOL)editing animated:(BOOL)animated
{
[super setEditing:editing animated:animated];
[self.tableView setEditing:editing animated:animated];
}
这里是代理方法的实现:
- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView
editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath {
return UITableViewCellEditingStyleNone;
}
- (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 = [[list objectAtIndex:fromRow] retain];
[list removeObjectAtIndex:fromRow];
[list insertObject:object atIndex:toRow];
[object release];
}
其中list为:
NSMutableArray *list;