2011-01-06 21 views
0

我有一個UISegmentedController控制TableView。 當selectedIndex被切換時我正在執行一個performFetch方法,其中有一個新的謂詞導致tableView內容發生變化。Animate table view performFetch就像在iPhone手機應用程序中未接電話

它工作正常,但我希望它在蘋果在手機應用程序中做的相同樣式中進行動畫處理,當您在所有最後和僅未接聽的電話之間切換時。

感謝任何幫助。

回答

0

OK成功地做到這一點 -

我不知道蘋果怎麼做,但我脫離了時,我已經意識到,預成型新獲取更昂貴的操作,那麼 -

第1步: 在我的例子中,我添加了一個mutableArray,用於收集用戶單擊分段控制器時要消失的單元格的所有索引。

在CellForRaw功能

我插入這個小的代碼:

- (void)configureCell:(PersonCell *)cell atIndexPath:(NSIndexPath *)indexPath { 
    // Configure the cell 
    if([fetchedResultsController objectAtIndexPath:indexPath]!=nil){ 
    Person *person = (Person *)[fetchedResultsController objectAtIndexPath:indexPath]; 
    cell.person = person; 
    cell.delegate=self; 

     if (person.state!=0) { 
      [activeIndexPaths addObject:indexPath]; 
     } 
    } 
} 

該插入片段I要過濾的陣列,供以後使用的對象的indexPath。

步驟2: 下一個函數被調用時在segmentedController作出的變更 -

-(void)ReloadTableViewWithNewPerdicate:(id)sender{ 

    UISegmentedControl *sc = (UISegmentedControl*)sender; 
    //[theTableView beginUpdates]; 
    Person *person; 
    switch (sc.selectedSegmentIndex) { 
     case 1: 
      for (int i=0; i<[activeIndexPaths count]; i++) { 
       person=(Person*)[fetchedResultsController objectAtIndexPath:[activeIndexPaths objectAtIndex:i]]; 
       [fetchedResultsController.managedObjectContext deleteObject:person]; 
      } 

      //[theTableView insertRowsAtIndexPaths:activeIndexPaths withRowAnimation:UITableViewRowAnimationRight]; 
      break; 
     case 0: 
      [fetchedResultsController.managedObjectContext rollback]; 
      break; 

    } 

該函數從fetchedResultsController.managedObjectContext 刪除原糖和:

- (void)controllerWillChangeContent:(NSFetchedResultsController *)controller{ 
} 
- (void)controller:(NSFetchedResultsController *)controller didChangeObject:(id)anObject atIndexPath:(NSIndexPath *)indexPath forChangeType:(NSFetchedResultsChangeType)type newIndexPath:(NSIndexPath *)newIndexPath { 
} 
- (void)controller:(NSFetchedResultsController *)controller didChangeSection:(id <NSFetchedResultsSectionInfo>)sectionInfo atIndex:(NSUInteger)sectionIndex forChangeType:(NSFetchedResultsChangeType)type { 
} 
- (void)controllerDidChangeContent:(NSFetchedResultsController *)controller { 
} 

函數負責刪除不需要的原始數據。 這基本上是你如何得到刪除的效果。

步驟3: 當用戶點擊主segmentedController按鈕的功能調用:

  [fetchedResultsController.managedObjectContext rollback]; 

字面上滾動一切恢復。

第4步: 最後importent步驟是回滾功能添加到ViewWillDisAppear,以確保在您的應用程序委託保存功能不會保存更改並從商店中刪除原糖。

希望它能幫助別人。

美好的一天。

+2

哇,這真是骯髒的黑客!我希望找到一個使用NSFetchedResultsController顯示/隱藏行的解決方案(因爲performFetch :)不會通知委託。但是這個代碼真的是黑客! – 2011-10-25 12:32:54

相關問題