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


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