我阅读本教程自定义的UITableViewCell与故事板 - 没有数据显示
ios-programming-customize-uitableview-storyboard
实现自定义的UITableViewCell。
在经典视图中的数据被正确地显示和更改这部分代码:
- (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];
}
ItemObject *obj=[[restArray objectAtIndex:indexPath.row] retain];
UILabel *objNameLabel = (UILabel *)[cell viewWithTag:101];
objNameLabel.text =obj.rag_soc;
UILabel *objDetailLabel = (UILabel *)[cell viewWithTag:102];
objDetailLabel.text=obj.via;
UIImageView *imv = [[UIImageView alloc]initWithFrame:CGRectMake(3,2, 44, 44)];
imv.image=[UIImage imageNamed:@"web_new.png"];
[cell.contentView addSubview:imv];
[imv release];
NSLog(@"%d",obj.nArrayIndex);
[obj release];
return cell;
}
当我运行该代码我没有看到任何数据。
你做在Interface Builder中的所有步骤,如创建标签和ImageView的,给他们适当的标签,否则你的代码将不引用任何东西 –