【发布时间】:2013-11-18 05:23:09
【问题描述】:
我有一个自定义 UITableViewCell 然后我有一个 UIImageView 里面。我可以使用相同的代码在 iphone 和应用程序的其他部分设置它的图像 ..和相同的 customcell ..但是我在某些部分没有显示图像。 以下是未显示部分的示例代码。
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
static NSString *CellIdentifier = @"CellIdentifier";
ItemsCell *cell = (ItemsCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil)
{
// cell = [[NSBundle mainBundle] loadNibNamed:@"CustomCell" owner:self options:nil];
NSArray *nib;
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
nib = [[NSBundle mainBundle] loadNibNamed:@"ItemsCell" owner:self options:nil];
}
else
{
nib = [[NSBundle mainBundle] loadNibNamed:@"ItemsCell_Ipad" owner:self options:nil];
}
cell = [nib objectAtIndex:0];
}
cell.titleLabel.text = [miscFileNameArray objectAtIndex:indexPath.row];
cell.artistLabel.text = [miscSizeArray objectAtIndex:indexPath.row];
if ([[UIDevice currentDevice]userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
cell.thumbnailImgView.image = [UIImage imageNamed:@"ext_default.png"];
}
else
{
cell.thumbnailImgView.image = [UIImage imageNamed:@"ipad_ext_defaul.png"];
NSLog(@"%@",cell.thumbnailImgView.image);
}
return cell;
}
当我记录 cell.thumbnailImgView.image 时,它会记录图像。但它仍然没有显示。在 iPhone 上它的工作我不知道为什么它不能在 iPad 上工作。
【问题讨论】:
-
您传递的图片名称是否正确?检查您的应用程序包中是否有使用此名称的图像
ipad_ext_defaul.png -
尝试为 iPad 记录 cell.thumbnailImgView 的边界,以确保它的大小不为零,或者不在屏幕某处。
-
使用断点并检查您的图像或图像名称是否正确??
-
是的,图像名称是正确的,我已经对其进行了三次检查,它还在构建阶段的复制包资源中添加。我真的不知道为什么它不起作用我在另一个类中使用了相同的代码。
-
@rdelmar 我尝试记录 NSLog(@"cell:%f",cell.thumbnailImgView.bounds.origin.x);它说 0.0000 所以它意味着它在某个地方。我该怎么办
标签: ios objective-c uitableview uiimage