私は、配列とドロップダウンリストで構成された 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];
}
まず、tableViewに更新を期待するように、beginUpdates
で伝えます。そして、関連するセクションを更新します(もし、tableViewが1つのセクションしか持たない場合は、セクション番号に0を渡します)。ここでアニメーションを指定しますが、お好みの効果が得られるように調整してください。その後、tableViewに対して、endUpdates
を呼び出します。UITableViewRowAnimationのtypedefで指定しています。
typedef enum {
UITableViewRowAnimationFade,
UITableViewRowAnimationRight,
UITableViewRowAnimationLeft,
UITableViewRowAnimationTop,
UITableViewRowAnimationBottom,
UITableViewRowAnimationNone,
UITableViewRowAnimationMiddle,
UITableViewRowAnimationAutomatic = 100
} UITableViewRowAnimation;
どれがいいのか、いろいろ試してみてください。tt;code>UITableViewRowAnimationNoneを選択しても、たまにいい効果があります。 テーブルの更新コードは以下の通りです。
[self.tableView beginUpdates];
[self.tableView reloadSections:[NSIndexSet indexSetWithIndex:0] withRowAnimation:UITableViewRowAnimationNone];
[self.tableView endUpdates];
を使うと、reloadSections:withRowAnimation:
関数を使うことができます。UITableViewクラスリファレンス](http://developer.apple.com/library/ios/#documentation/uikit/reference/UITableView_Class/Reference/Reference.html)をご確認ください。
こちらのreloadData with Animationが既に回答されていますのでご覧ください。