ios - 自定义 UITableViewCell ImageView 未显示

标签 ios objective-c uitableview

好吧,我将复杂的应用程序修剪成一个简单的版本,以便每个人都能理解。因此,首先我从服务器下载一个 zip 文件,将其解压缩并将其放入缓存目录文件夹中。 AppDelegate 中发生的所有事情都可以很好地解压缩和存储图像。在调用 tableviews veiwdidload 方法时,我调用了一个函数来查找 iPhone 缓存目录文件夹中的图像文件。找到成功的图像文件后,我取该图像的文件路径

.h

@property (nonatomic, strong) IBOutlet UIImageView *theImage;

.m

NSString * photo;

NSString * photoType = @"6F0C437D-1BB2-482B-BF11-39BCAB668E4C";

photo = [NSString stringWithFormat:@"BANNERLOGO%@.png", photoType];


NSArray *cachesPaths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);


NSString * cacheDir = [cachesPaths objectAtIndex:0];

cacheDir = [cacheDir stringByAppendingPathComponent:@"1D2EA159-A312-4FB5-8FE5-B95879B242BB"];


NSString * photoPath = [cacheDir stringByAppendingPathComponent:photo];

BOOL success = [fileManager fileExistsAtPath:photoPath];

if (!success) {
    NSLog(@"Error!!");
}

UIImage *image = [UIImage imageWithContentsOfFile:photoPath];

[self.theImage setImage:image];

所以这是我的问题。我似乎无法弄清楚为什么我抓取的图像没有出现?有谁知道为什么会这样?奇怪的是,当我设置 tableview 单元格的颜色时,它会像我期望的那样变成灰色。

    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{



    CustomCell *cell = (CustomCell *)[tableView dequeueReusableCellWithIdentifier:@"MainCell"];

    if (cell == nil) {


        cell = [[CustomCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"MainCell"];

    }

    //DoesNot
    cell.bannerImageView.image = self.theImage.image;


    //Shows up in cell
   cell.backgroundColor = [UIColor colorWithRed:0.9f green:0.9f blue:0.9f alpha:1.0f];

    return (UITableViewCell *)cell;
}

如果有帮助的话,这是我的自定义单元格类的代码。

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{ self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
 CGRect contentRect = self.contentView.bounds;

        contentRect.size.height = 56.0;


        self.bannerImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 300, 56)];

        self.bannerImageView.contentMode = UIViewContentModeScaleAspectFit;

        [self.contentView addSubview:bannerImageView];



    }

    return self;
}

感谢提前指导!

最佳答案

尝试设置 imageView 背景颜色(比如绿色),看看您是否有布局问题或图像加载问题。

关于ios - 自定义 UITableViewCell ImageView 未显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24663963/

相关文章:

ios - 如何将自定义类添加为数据源并委托(delegate)给 NSTableView

iphone - 一起播放 .mp3 文件的两个循环

iphone - tabBar 和 navigationBar 大小奇怪的返回值

ios - 翻转动画中途更改 UIImageView 图像

iPhone 获取 UITextField 的父 View

ios - “NSInternalInconsistencyException” - 无法在 uinavigationcontroller ios 6 上推送 uitableviewcontroller

ios - 为标识符 ((null)) 注册的无效 Nib - Nib 必须恰好包含一个顶级

ios - UIPageViewController 页面指示器位置

ios - 在另一个定义中使用台风组装模型属性

ios - 是否可以使用 UIPageControl 来控制 UITableView 的移动?