2014-09-11 6 views
0

У меня есть UITableView с несколькими строками. Я хочу, чтобы выбранная ячейка всегда находилась в самом верхнем положении UITableView, а ячейки после выбранной ячейки должны были окунуться в нижнюю часть.TableView Animation

Для анимации к началу Я использовал этот код:

- (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

+0

Принцип тот же. Вы можете настроить код выше, чтобы сделать это. – freshking