2014-09-11 62 views
0

我有一个UITableView行。我希望所选单元始终位于UITableView的最顶端位置,并且选定单元格之后的单元格应该动画到底部。TableView动画

对于动画到顶部我用这个代码:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath; 
{ 
    CGFloat height = 44.0f; //cell height 

    tableView.contentInset = UIEdgeInsetsMake(0, 0, height * indexPath.row, 0); 

    [tableView setContentOffset:CGPointMake(0, (indexPath.row * height)) 
       animated:YES]; //set the selected cell to top 
} 

我的问题是我怎么能在选定单元底部后,动画细胞?

回答

0
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath; 
{ 
    // I will assume you have your tableView's data stored in an array: _dataArray 

    [_tableView beginUpdates]; 

    [_dataArray insertObject:[_dataArray objectAtIndex:indexPath.row] atIndex:0]; 
    [_dataArray removeObjectAtIndex:([_dataArray count]-1)]; 

    [_tableView reloadSections:[NSIndexSet indexSetWithIndex:0] withRowAnimation:UITableViewRowAnimationAutomatic]; 

    [tableView endUpdates]; 
} 
+0

我想要将所选索引上方的行顶部和底部的选定索引下面的行设为底部, – swetha 2014-09-11 11:40:17

+0

原理相同。你可以调整上面的代码来做到这一点。 – freshking 2014-09-11 11:47:36