开发者

change the order of tableviewcells with animation

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜