在我的表格单元格中添加了标志。使用情节提要将 UIImageView 放在原本为空的原型单元格中并很好地调整其大小(47x34)。然后在这里添加代码:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell1";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
if (cell == nil) {
cell = [[UITableViewCell alloc]
initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
cell.textLabel.text = [[[content objectAtIndex:indexPath.section] objectForKey:@"rowValues"] objectAtIndex:indexPath.row];
cellTxt = cell.textLabel.text;
UIImageView *flagImg = (UIImageView *) [cell viewWithTag:10];
NSString *imgFilenm = [cellTxt stringByAppendingString:@".jpg"];
flagImg.image = [UIImage imageNamed: imgFilenm ];
cell.imageView.frame = CGRectMake(0, 0, 47, 34); // not needed, and doesn't fix it
return cell;
}
图像出现了,但向左挤压到只有大约 8 个像素。为什么?以及如何纠正?谢谢!
原件:
** 编辑 ** 我将单元格文本切换为我添加的 UILabel。这是代码:
UILabel *nameLbl = (UILabel *)[cell viewWithTag:5];
nameLbl.text = [[[content objectAtIndex:indexPath.section] objectForKey:@"rowValues"] objectAtIndex:indexPath.row];
以及它在故事板中的样子:
但现在旗子甚至没有出现。