我閱讀本教程自定義的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的,給他們適當的標籤,否則你的代碼將不引用任何東西 –