2011-01-06 13 views
0

私はTableViewを制御するUISegmentedControllerを持っています。 selectedIndexが切り替わったとき、私はtableViewコンテンツの変更を引き起こす新しい述語でperformFetchメソッドを実行しています。アニメーションテーブルビューperformFetchは、iPhoneの電話アプリの不在着信のようです。

それはうまく動作しますが、Appleの電話アプリケーションと同じスタイルでアニメーション化したいときには、すべてのrecentsとunsupported callsの間を切り替える必要があります。

は助けに感謝します。

答えて

0

OKはそれを行うために管理 -

を私はAppleがそれを行う方法を知らないが、私は、その新しいフェッチを予備成形することは、より高価な操作であることを認識しているときに私が脱退 -

ステップ1: 中を私の場合は、私はユーザーがセグメント化されたコントローラをクリックすると消えたいセルのすべてのインデックスを収集するmutableArrayを追加しました。

- (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を挿入:私はこの小さなコードを挿入CellForRaw関数で

ステップ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 からのRAWおよび削除:

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

  [fetchedResultsController.managedObjectContext rollback]; 

文字通りすべてをロール:ユーザが機能を呼び出すメインsegmentedControllerボタンをタップ

ステップ4: 最終にとって必須のステップは、アプリのデリゲートで保存する機能は文句を言わない変更を保存し、ストアからのRAWを削除することを確認するViewWillDisAppearへのロールバック機能を追加することです。

誰かを助けてくれることを願っています。

おやすみなさい。

+2

うわー、それは本当に汚いハッキングです!私は、NSFetchedResultsController(performFetch :)がデリゲートに通知しないので、行の表示/非表示のソリューションを見つけることを望んでいました。しかし、このコードは本当にハックです! –

+0

私はよりエレガントなものを見つけることができたら、私に知らせてくれることを願っています。 BTWはこのHackは素晴らしい作品です:)。 – shannoga

+0

こんにちは@shannogaは、これを行うためにcoredataまたはこれ以上の方法なしでこのアニメーションを使用することは可能です。 – iDeveloper

関連する問題