在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
执行此操作的
方法是实现表视图数据源协议。 最关键的方法如下:
- (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];
}
如果表中有多个部分,或者视图中有多个表,则会出现差异。 但这是基本思想。