0

viewDidLoadには、次のコードがあります。

ProvRec *provRec = [[ProvRec alloc]init];
provRec.status = [NSString stringWithUTF8String:(char *)sqlite3_column_text(statement,3)
                            ];
provRec.desc = [NSString stringWithUTF8String:(char *)sqlite3_column_text(statement,4)
                            ];
[listOfItems addObject:provRec];

これらのレコードをcellForRowAtIndexPath:(NSIndexPath *)indexPathのTableViewに表示するにはどのように呼び出す必要がありますか

4

1 に答える 1

2

それを行う方法は、テーブル ビュー データソース プロトコルを実装することです。最も重要な方法は次のとおりです。

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

    static NSString *CellIdentifier = @"Cell";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
    }

    ProvRec *provRec = [listOfItems objectAtIndex:indexPath.row];
    cell.textLabel.text = provRec.status;
    cell.detailTextLabel.text = provRec.desc;
    return cell;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {

    return [listOfItems count];
}

テーブルに複数のセクションがある場合、またはビューに複数のテーブルがある場合、変動があります。しかし、これが基本的な考え方です。

于 2012-06-20T23:39:08.873 に答える