2014-12-18 67 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

否則,如果你有一個筆尖或故事板你使用然後設置在您使用的原型細胞的默認。

相關問題