开发者

change the order of tableviewcells with animation

开发者 https://www.devze.com 2023-03-01 01:48 出处:网络
Is there a way to change the order of tableviewcells with animation? I want to slide up or down cells and change the ordering.

Is there a way to change the order of tableviewcells with animation? I want to slide up or down cells and change the ordering. But i dont know if it i开发者_JAVA技巧s possible with animation? I need help. Thanks,Tintin


You could do that UITableView's edit mode.

Iphone sdk tutorial Add/Delete/Reorder UITableView row.


In this code dataArray is the name of my array you change it with your own array name

- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath {

    return YES;

}

- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)sourceIndexPath toIndexPath:(NSIndexPath *)destinationIndexPath {

    NSString *stringToMove = [[self.dataArray objectAtIndex:sourceIndexPath.row] retain];
    [self.dataArray removeObjectAtIndex:sourceIndexPath.row];
    [self.dataArray insertObject:stringToMove atIndex:destinationIndexPath.row];
    [stringToMove release];
    [tableView reloadData];

}
0

精彩评论

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