objective-c - 从外部类调用时,Obj-c UIImageView 为空

标签 objective-c ios uiimageview

我有一个 UIViewController,其中包含一个已正确连接的 UIImageView(我可以在 Controller 中设置图像)。

我还设置了一个 iVar 使用

UIImageView *_imgQRCode;

和属性使用

@property (strong, nonatomic) IBOutlet UIImageView *imgQRCode;

合成使用:

@synthesize imgQRCode = _imgQRCode;

但是当我像下面这样调用时,图像什么也没有发生,当我在 Xcode 中检查时,引用是内存引用是 0x00000000。请注意,代码在 ViewController 内部调用时有效。以下是从任何其他 View Controller 调用的, Controller 实例化如下:

QRPopupViewController *qrPop = [[QRPopupViewController alloc] initWithNibName:@"QRPopupViewController" bundle:nil];

[controller.imgView setImage:[UIImage imageNamed:@"sample.png"]];

关于如何解决这个问题以及为什么我得到 null 有什么想法吗?

最佳答案

首先:网点应该很弱

@property (weak, nonatomic) IBOutlet UIImageView *imgQRCode;

您必须将 imgQRCode socket 连接到您的 viewController,并且您可以在 viewDidLoad 中使用它。

关于objective-c - 从外部类调用时,Obj-c UIImageView 为空,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13623992/

相关文章:

ios - 在 viewDidLoad 中初始化的变量范围到另一个方法

ios - Xcode 6 : "Simulator in Use" error shows even though the simulator is NOT in use

ios - 深色模式比浅色模式需要更多时间加载图片

ios - Swift,自定义 UITableViewCell 和 UIImageView。需要将单元格调整为图像高度

iphone - AES 256/CBC/Withoutpadding in objective-c

iOS:重置 UIPickerView EXC_BAD_ACCESS 错误

objective-c - 将选定的日期和时间保存到plist中

ios - 如何在 Swift 中将多个重叠的 UIImage 合并为一个 UIImage?

iphone - 将十六进制字符串转换为int时出现奇怪的结果

iphone - 如何获取 iTunes 应用程序描述?