IBOutlet在drawRect方法中为零(IBOutlet is nil in drawRect method)

编程入门 行业动态 更新时间:2024-10-15 00:27:24
IBOutlet在drawRect方法中为零(IBOutlet is nil in drawRect method)

我有一个带有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; }

更多推荐

本文发布于:2023-08-07 02:45:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1459409.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:为零   方法   drawRect   IBOutlet   nil

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!