我在故事板上创建了一个UITableViewCell原型单元,然后将它链接到从UITableViewCell继承的ImageViewCell。我为原型单元上的每个控件创建了IBOutlet,它包含一些UILabel和一个UIImageView。当我试图将数据填充到这些控件中时,UILabel工作得很好,但是UIImageView总是不显示任何图像,也不会显示任何图像。代码:
@interface ImageTableViewCell : UITableViewCell
@property (readonly, nonatomic, strong) Post *post;
// set value for post
- (void)setPost:(Post *)post;
@end
@implementation ImageTableViewCell
{
__weak IBOutlet UILabel *titleLabel;
__weak IBOutlet UILabel *descriptionLabel;
__weak IBOutlet UILabel *pointLabel;
__weak IBOutlet UIImageView *imageView;
}
- (void)setPost:(Post *)post
{
_post = post;
// update ui
titleLabel.text = self.post.title;
descriptionLabel.text = self.post.descriptions;
pointLabel.text = self.post.point;
[imageView setImage:[UIImage imageNamed:@"mylocalimage.png"]];
}
@end在我的控制器里:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
if(feedData == nil || [feedData count] == 0)
{
return nil;
}
NSDictionary *postData = [feedData objectAtIndex:indexPath.row];
// prepare data to pass to table view cell
Post *post = [[Post alloc] init];
post.title = [postData objectForKey:@"title"];
post.descriptions = [postData objectForKey:@"description"];
post.total_likes = [postData objectForKey:@"total_likes"];
post.total_shares = [postData objectForKey:@"total_shares"];
post.image = [postData objectForKey:@"image"];
ImageTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"ImageCell"];;
if(cell == nil)
{
cell = [[ImageTableViewCell alloc] init];
}
[cell setPost:post];
return cell;
}所有的UILabel都工作得很好,但是UIImageView的形象从来没有被设定过,我试着用一个本地的图像来设置它,但仍然不起作用。经过一些调查,我发现当我为imageView设置图像时,它总是为零。那么我该如何克服这个问题呢?
更新
链接图像

发布于 2014-10-08 09:45:42
尝试将UIImageView的变量名更改为"imageView“以外的其他内容。原因是UITableViewCell本身有一个名为"imageView“的属性。因此,当您设置属性时,它必须尝试设置未链接到您的出口的超类属性,从而得到结果。
https://stackoverflow.com/questions/26252681
复制相似问题