LoginSignup
20
20

More than 5 years have passed since last update.

TableViewが呼び出すメソッドの順序とデータ表示・更新方法

Last updated at Posted at 2012-11-22

FacebookからFQLを使って取得したデータをTableViewに表示させる方法・その時に呼び出されるメソッドの順序そしてTableVIewの更新方法

[ListViewController numberOfSectionsInTableView:]
[ListViewController tableView:titleForHeaderInSection:]
[ListViewController tableView:titleForHeaderInSection:]
[ListViewController tableView:numberOfRowsInSection:]
[ListViewController tableView:cellForRowAtIndexPath:]
[ListViewController tableView:cellForRowAtIndexPath:]
[ListViewController tableView:cellForRowAtIndexPath:]
[ListViewController tableView:cellForRowAtIndexPath:]
[ListViewController tableView:cellForRowAtIndexPath:]
[ListViewController tableView:cellForRowAtIndexPath:]
[ListViewController tableView:cellForRowAtIndexPath:]
[ListViewController tableView:titleForHeaderInSection:]
  • numberOfSectionIntableView : セクション数を返す
  • titleForHeaderInSection : セクション毎のヘッダーを返す
  • numberOfRowsInsection : セクション内にあるデータ数(行数)を返す
  • cellForRowAtIndexPath : セル毎のオブジェクトを返す。取得したデータの表示はここで行なっている。

Facebookからデータを取得 -> TableViewに表示、というロジックなのでデータ取得後にreloadメソッドを呼び出してTableViewを更新している。以下はその時のサンプル。

TableViewの更新方法
[FBRequestConnection
    startWithGraphPath:@"/fql"
    parameters:queryParam
    HTTPMethod:@"GET"
    completionHandler:^(
        FBRequestConnection* connection,
        id result,
        NSError* error) {
            self.data = (NSArray *)[result objectForKey:@"data"];
            [self.tableView reloadData];
}];

参考にしたページ : Table View入門 #1

20
20
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
20
20