79

UITableView配列とドロップダウンリストから取り込まれたものがあります。
ドロップダウンリストの行を選択すると、配列に新しい値が挿入され、テーブルビューがリロードされます。

新しい配列の内容でテーブルビューをアニメーション化する方法は?

1行ずつ表示したいアニメーションのようなものです。私はこの方法を試しました

- (void)reloadRowsAtIndexPaths:(NSArray )indexPaths withRowAnimation:(UITableViewRowAnimation)animation { 
NSIndexPath rowToReload = [NSIndexPath indexPathForRow:[names count] inSection:0];
 NSArray* rowsToReload = [NSArray arrayWithObjects:rowToReload, nil]; 
[tableDetails reloadRowsAtIndexPaths:rowsToReload withRowAnimation:UITableViewRowAnimationNone];
 }
4

11 に答える 11

125

正解に追加するには、すべてのセクションをリロードするUITableView場合は、次の操作を行う必要があります。

オブジェクトC

NSRange range = NSMakeRange(0, [self numberOfSectionsInTableView:self.tableView]);
NSIndexSet *sections = [NSIndexSet indexSetWithIndexesInRange:range];
[self.tableView reloadSections:sections withRowAnimation:UITableViewRowAnimationAutomatic];

迅速

let range = NSMakeRange(0, self.tableView.numberOfSections)  
let sections = NSIndexSet(indexesIn: range)               
self.tableView.reloadSections(sections as IndexSet, with: .automatic) 

これにより、テーブル ビュー内のすべてがアニメーション付きで再読み込みされます。偉ぶって。

于 2014-01-20T16:45:59.057 に答える
74

スウィフト5:

UIView.transition(with: tableView, duration: 1.0, options: .transitionCrossDissolve, animations: {self.tableView.reloadData()}, completion: nil)

スイフト3

UIView.transition(with: myTableView, duration: 1.0, options: .transitionCrossDissolve, animations: {self.myTableView.reloadData()}, completion: nil)

スイフト2

UIView.transitionWithView(myTableView, duration: 1.0, options: .TransitionCrossDissolve, animations: {self.myTableView.reloadData()}, completion: nil)

私はSwiftでこれに行きました

于 2016-07-14T15:43:55.247 に答える
54

この方法を使用して、

[_tableView reloadSections:[NSIndexSet indexSetWithIndex:0] withRowAnimation:UITableViewRowAnimationFade];
于 2013-01-29T06:43:58.467 に答える
23

まず、tableViewに。で更新を期待するように指示しますbeginUpdates。次に、関連するセクションを更新します(tableViewにセクションが1つしかない場合は、セクション番号にゼロを渡します)。ここでアニメーションを指定します。アニメーションをいじって、必要な効果を得ることができます。その後endUpdates、tableViewを呼び出します。UITableViewRowAnimationのtypedefは、以下を指定します。

typedef enum {
   UITableViewRowAnimationFade,
   UITableViewRowAnimationRight,
   UITableViewRowAnimationLeft,
   UITableViewRowAnimationTop,
   UITableViewRowAnimationBottom,
   UITableViewRowAnimationNone,
   UITableViewRowAnimationMiddle,
   UITableViewRowAnimationAutomatic = 100
} UITableViewRowAnimation;

遊んで、どれが欲しいか見てみましょう。選択するだけでもUITableViewRowAnimationNone良い効果が得られる場合があります。以下のテーブル更新コード:

    [self.tableView beginUpdates];
    [self.tableView reloadSections:[NSIndexSet indexSetWithIndex:0] withRowAnimation:UITableViewRowAnimationNone];
    [self.tableView endUpdates];
于 2013-01-29T06:53:17.737 に答える
8

関数を使用できreloadSections:withRowAnimation:ます。UITableView クラス リファレンスを確認してください。

あなたの質問にすでに答えているアニメーションでこのreloadData を確認してください。

于 2013-01-29T06:38:51.587 に答える
4

以下のメソッドは、アニメーション用の tableView でサポートされています。

- (void)reloadSections:(NSIndexSet *)sections withRowAnimation:(UITableViewRowAnimation)animation NS_AVAILABLE_IOS(3_0);

使用法 :

//Reload tableView with animation
[self.tableView reloadSections:[NSIndexSet indexSetWithIndex:0] withRowAnimation:UITableViewRowAnimationRight]; 

利用可能なさまざまなタイプのアニメーションは次のとおりです。

typedef NS_ENUM(NSInteger, UITableViewRowAnimation) {
UITableViewRowAnimationFade,
UITableViewRowAnimationRight,           // slide in from right (or out to right)
UITableViewRowAnimationLeft,
UITableViewRowAnimationTop,
UITableViewRowAnimationBottom,
UITableViewRowAnimationNone,            // available in iOS 3.0
UITableViewRowAnimationMiddle,          // available in iOS 3.2.  attempts to keep cell centered in the space it will/did occupy
UITableViewRowAnimationAutomatic = 100  // available in iOS 5.0.  chooses an appropriate animation style for you    };

これが役立つことを願っています!

于 2013-12-24T14:11:34.917 に答える
4

私はこれを試しましたTableAnimated、スムーズなアニメーションを使用しています

// テーブル ビューをリロードする場所にこのコードを挿入します

dispatch_async(dispatch_get_main_queue(), ^{
    [UIView transitionWithView:<"TableName"> 
                      duration:0.1f 
                       options:UIViewAnimationOptionTransitionFlipFromRight 
                    animations:^(void) {
                        [<"TableName"> reloadData];
                    } completion:NULL];        
});
于 2016-02-24T06:02:50.200 に答える