TableViewで指定したセルの位置までスクロール
NSIndexPath *indexPath = [NSIndexPath IndexPathForRow:_objects.count inSection:0];
[tableView insertRowsAtIndexPaths:[NSArray arrayWithObject:indexPath]
withRowAnimation:UITableViewRowAnimationAutomatic];
// ココ
[tableView scrollToRowAtIndexPath: indexPath atScrollPosition:UITableViewScrollPositionTop animated:YES];
上のコードではTableViewに項目を最下位の行に追加していくなかで、追加した位置までスクロールするというものです。
TableViewの更新
// TableView全体を更新 [tableView reloadData]; // 指定したセクションを更新 [tableView reloadSections:[NSIndexSet indexSetWithIndex:0] withRowAnimation:UITableViewRowAnimationNone]; // 指定した行を更新(複数指定も可能) [tableView reloadRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationNone];
。。。まぁ何かと使えます。reloadDataは簡単に実装できます。
NSMutableArrayの値を変更
NSMutableArray *objects = [[NSMutableArray alloc] init];
for (int i = 0; i < 3; i++) {
[objects addObject:[NSString stringWithFormat:@"sample%d", i]];
}
[objects replaceObjectAtIndex:1 withObject:@"test"];
追加・削除は当たり前ですが値の変更もよくあると思います。
。。。備忘録です。
0 件のコメント:
コメントを投稿