2009年
7月 28
久しぶりに iPhone アプリネタです。UITableView を指定した場所までスクロールさせる方法です。
どの方法も NSIndexPath で UITableView のセルの位置を指定して、UITableViewScrollPosition で指定したセルを UITableView のどの位置に持ってくるかを指定します。これによって、指定したセルを UITableView の一番上や一番下、真ん中などを指定することが可能です。
セルを指定してスクロールさせる
NSIndexPath* indexPath = [NSIndexPath indexPathForRow:0 inSection:0]; [tableView scrollToRowAtIndexPath:indexPath atScrollPosition:UITableViewScrollPositionTop animated:NO];
最後に選択したセルの位置にスクロールさせる
[tableView scrollToNearestSelectedRowAtScrollPosition:UITableViewScrollPositionTop animated:YES];
セルを選択状態にしてスクロールさせる
NSIndexPath* indexPath = [NSIndexPath indexPathForRow:0 inSection:0]; [tableView selectRowAtIndexPath:indexPath animated:YES scrollPosition:UITableViewScrollPositionTop];
UITableViewScrollPosition
typedef enum {
UITableViewScrollPositionNone,
UITableViewScrollPositionTop,
UITableViewScrollPositionMiddle,
UITableViewScrollPositionBottom
} UITableViewScrollPosition;
関連する投稿
Leave a Reply
Additional comments powered by BackType
Recent Comments