2014-12-18 68 views
0

我在我的表格视图单元格上有一个图像属性。我想将此图像填充到图像中。如何在iOS中设置表格视图单元格属性的初始值

我的手机是这样的:

//.h 
@interface GAFriendStatusTableViewCell : PFTableViewCell 
@property (weak, nonatomic) IBOutlet UIImageView *friendImage; 

@end 

//.m 
#import "GAFriendStatusTableViewCell.h" 

@implementation GAFriendStatusTableViewCell 

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier 
{ 
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]; 
    if (self) { 
     self.friendImage.image = [UIImage imageNamed:@"user.png"]; 
    } 
    return self; 
} 

- (void)awakeFromNib 
{ 
    // Initialization code 
} 

@end 

这不设置图像。如何在单元类中设置此单元格的图像?

回答

3

既然你的图像视图是一个IBOutlet,我假设你已经在.xib或storyboard中定义了你的单元格布局。既然如此,你的初始化代码应该在awakeFromNib方法中。这是从nib创建单元格时调用的方法。这就是为什么//Initialization code评论是在那里。在这种情况下永远不会调用initWithStyle:reuseIdentifier:,这就是为什么你的图像没有出现。

0

将其设置为- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath

否则,如果你有一个笔尖或故事板你使用然后设置在您使用的原型细胞的默认。

相关问题