2013-10-21 72 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

相關問題