2

私は Iphone アプリケーションを開発しています。これには 8 つのセルを持つ UITableview が含まれています。次のコードを使用して、テーブル ビューを自動スクロールし、格納するセルの合計を配列に取得します。

-(void)viewDidAppear:(BOOL)animated{

    [tableView scrollToRowAtIndexPath:[NSIndexPath indexPathForRow:[musicGenre count]-1 inSection:0] atScrollPosition:UITableViewScrollPositionBottom animated:YES];

    }

これは完全に機能しています。しかし、今はこれを下から上に同時にスクロールしたい(ロード時間)。これを実装するにはどうすればよいですか? 前もって感謝します。

4

1 に答える 1

9

からUITableView継承しUIScrollViewているため、次のようなものを使用できます。

- (void)viewDidAppear:(BOOL)animated{

  [table setContentOffset:CGPointMake(0.0, table.contentSize.height - table.bounds.size.height)
                 animated:NO];  

  [tableView scrollToRowAtIndexPath:[NSIndexPath indexPathForRow:[musicGenre count]-1 inSection:0]                                                
                   atScrollPosition:UITableViewScrollPositionBottom
                           animated:YES];
}

編集:

上から下への最初の動きもアニメーション化したい場合は、次のようにします。

- (void)viewDidAppear:(BOOL)animated{

  [table setContentOffset:CGPointMake(0.0, table.contentSize.height - table.bounds.size.height)
                 animated:YES]; 

  [tableView scrollToRowAtIndexPath:[NSIndexPath indexPathForRow:[musicGenre count]-1 inSection:0]                                                
                   atScrollPosition:UITableViewScrollPositionBottom
                           animated:YES];
}

しかし、ユーザー エクスペリエンスを考慮してください。それだけの量のアニメーションが必要ですか? ユーザー (特にアプリを頻繁に使用する場合) は時間を無駄にしたくないからです。アニメーションは、ユーザー エクスペリエンスを向上させ、ワークフローの遅延を引き起こさない場合に優れています。

EDIT2:(現在の位置から)上にスクロールするには、次を使用できます:

 [table setContentOffset:CGPointZero
                animated:YES];
于 2012-06-09T13:25:03.120 に答える