我有一个带有xib的UIView子类,名为RoundedImageView ,它只实现了drawRect方法。 xib包含一个带有插座的AsyncImageView (它是UIImageView的子类)。 此RoundedImageView是自定义表视图单元格的一部分。 在这个单元格的awakeFromNib方法中, RoundedImageView不是nil,但它的AsyncImageView出口是零。 为什么会发生这种情况?我该如何解决这个问题?
I have a UIView subclass with a xib called RoundedImageView, which only implements the drawRect method. The xib contains an AsyncImageView (which is a subclass of UIImageView) with an outlet. This RoundedImageView is part of a custom table view cell. In the awakeFromNib method of this cell, the RoundedImageView is not nil, but it's AsyncImageView outlet is nil. Why is this happening and how do I fix this?
最满意答案
在与OP讨论聊天之后,问题结果是表格单元格/ RoundedImageView在一个笔尖中,而带有AsycImageView在另一个笔尖中。 解决方案是从单元格中删除RoundedImageView ,并将其nib加载到单元格的awakeFromNib方法中:
@implementation InviteFriendsImageVIew - (void)awakeFromNib { UINib *imageViewNib = [UINib nibWithName:@"RoundedImageView" bundle:nil]; RoundedImageView *imageView = [imageViewNib instantiateWithOwner:nil options:nil][0]; imageView.frame = // set frame here [self addSubView:imageView]; self.roundedImageView = imageView; }After discussion with OP in chat, the issue turned out to be that the table cell / RoundedImageView was in one nib, and RoundedImageView with AsycImageView was in another. The solution was remove RoundedImageView from the cell, and load its nib in the cell's awakeFromNib method:
@implementation InviteFriendsImageVIew - (void)awakeFromNib { UINib *imageViewNib = [UINib nibWithName:@"RoundedImageView" bundle:nil]; RoundedImageView *imageView = [imageViewNib instantiateWithOwner:nil options:nil][0]; imageView.frame = // set frame here [self addSubView:imageView]; self.roundedImageView = imageView; }更多推荐
发布评论