我不確定這是否爲故事板錯誤。我用一個自定義單元格創建了一個項目。從自定義單元格加載UIImageView子類
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"HomeGameTurnCell";
HomeTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[HomeTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
自定義單元格有一些圖像視圖。其中一個圖像視圖是一個子類。
@interface HomeTableViewCell : UITableViewCell
@property (strong, nonatomic) IBOutlet RoundedProfilePicture *profilePictureImageView;
@property (strong, nonatomic) IBOutlet UIImageView *turnThumbnailImage;
@property (strong, nonatomic) IBOutlet UILabel *usernameLabel;
@property (strong, nonatomic) IBOutlet UILabel *lastPlayedLabel;
@end
的RoundedProfilePicture子只是有以下幾點:
-(id)init {
NSLog(@"%s",__PRETTY_FUNCTION__);
self = [super init];
if (self) {
[self setupView];
}
return self;
}
- (void)setupView
{
NSLog(@"%s",__PRETTY_FUNCTION__);
self.clipsToBounds = YES;
self.layer.cornerRadius = self.bounds.size.width/2;
self.layer.borderWidth = 3;
self.layer.borderColor = [UIColor darkGrayColor].CGColor;
}
什麼我發現是,RoundedProfilePicture方法不會被調用。在故事板內,我設置了一個原型單元格和正確的標識符。我也有圖像視圖設置爲正確的自定義類。但它似乎沒有生效,有什麼我失蹤/可以檢查?
謝謝,但我不確定這是如何實現的,你有這樣的例子嗎?此外,這個特定的更改會影響UIImageView類未被加載的問題嗎? – StuartM
我更新了我的答案 - 而不是 - (id)init使用我的initWithStyle –
再次感謝。抱歉是一種痛苦,但我實際上並沒有理解第一部分prepareForReuse如何用於我的上下文。我實際上已經嘗試將init的init從initWithStyle更改爲init以查看是否有任何區別,但是我可以改變它。 – StuartM