2013-10-21 70 views
0

我在UITableView中有一个部分,一旦我点击它,4个动画单元格下拉,然而,问题是,当它们下降时,它们往下走过视图(屏幕),而且你无法除非你向下滚动才能看到它们。我怎样才能做到这一点,所以一旦点击了该部分,它就会推动整个视图,显示下拉菜单中的所有单元格?这是我的代码:UITableView中的动画单元格

- (void) sectionOpened : (NSInteger) section{ 

    SectionInfo *array = [self.sectionInfoArray objectAtIndex:section]; 
    array.open = YES; 

    NSInteger count = [array.category.list count]; 
    NSMutableArray *indexPathToInsert = [[NSMutableArray alloc] init]; 
    for (NSInteger i = 0; i<count;i++) 
    { 
     [indexPathToInsert addObject:[NSIndexPath indexPathForRow:i inSection:section]]; 
    } 

    NSMutableArray *indexPathsToDelete = [[NSMutableArray alloc] init]; 
    NSInteger previousOpenIndex = self.openSectionIndex; 
    if (previousOpenIndex != NSNotFound) 
    { 
     SectionInfo *sectionArray = [self.sectionInfoArray objectAtIndex:previousOpenIndex]; 
     sectionArray.open = NO; 
     NSInteger counts = [sectionArray.category.list count]; 
     [sectionArray.sectionView toggleButtonPressed:FALSE]; 
     for (NSInteger i = 0; i<counts; i++) 
     { 
      [indexPathsToDelete addObject:[NSIndexPath indexPathForRow:i inSection:previousOpenIndex]]; 
     } 
    } 
    UITableViewRowAnimation insertAnimation; 
    UITableViewRowAnimation deleteAnimation; 
    if (previousOpenIndex == NSNotFound || section < previousOpenIndex) 
    { 
     insertAnimation = UITableViewRowAnimationTop; 
     deleteAnimation = UITableViewRowAnimationBottom; 
    } 
    else 
    { 
     insertAnimation = UITableViewRowAnimationBottom; 
     deleteAnimation = UITableViewRowAnimationTop; 
    } 

    [atableView beginUpdates]; 

    [atableView insertRowsAtIndexPaths:indexPathToInsert withRowAnimation:UITableViewRowAnimationTop]; 
    [atableView deleteRowsAtIndexPaths:indexPathsToDelete withRowAnimation:deleteAnimation]; 


    [atableView endUpdates]; 

    self.openSectionIndex = section; 

} 

任何想法?

回答

0

你试过用这个tableView方法吗?

- (void)scrollToRowAtIndexPath:(NSIndexPath *)indexPath atScrollPosition:(UITableViewScrollPosition)scrollPosition animated:(BOOL)animated 

所以你可以试试。

[atableView scrollToRowAtIndexPath:indexPathToInsert atScrollPosition: UITableViewScrollPositionTop animated:YES]; 
+0

嗯由于某种原因,这没有奏效? –

+0

您是否在呼叫endUpdates之后执行此操作? – aahrens

相关问题