我正在使用 Storyboard 做一个简单的应用程序,它有一个 View 和一个UITableView
with a UITableViewCell
,它可以导航到另一个UIView
.
所以必须编写代码来填充表格视图上的单元格。
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *cellIdentifier = @"SampleCell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:cellIdentifier];
NSLog(@"cai no init da cell");
}
GPItem *item = [self.items objectAtIndex:indexPath.row];
cell.textLabel.text = @"Post";
cell.detailTextLabel.text = item.imageURL;
return cell;
}
我意识到代码if (cell == nil) { ...
永远不会执行,所以我真的需要使用 Storyboard 中的单元格来执行此操作吗?
谢谢。