我有一个 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/