UIViewController IBOutlets是零 [英] UIViewController IBOutlets are nil

查看:202
本文介绍了UIViewController IBOutlets是零的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有两个标签的UIViewController类和一个设置为IBOutlets的UIImageView,我在xib中连接了这个插座,我已经仔细检查它们是否正确连接,但是当我在调试器中检查它们的值时它们是0x0所以我不能以编程方式改变它们。关于我可能做错的任何想法。

I have an UIViewController class with two labels and a UIImageView set as IBOutlets, and I have this outlets connected in my xib, I have double checked they are connected properly, however when I check the their value in the debugger they are 0x0 so I cant change them programatically. Any ideas on what I might be doing wrong.

继承我的代码的头文件:

Heres the header file of my code:

#import <UIKit/UIKit.h>


@interface PlateDetailViewController : UIViewController {

     IBOutlet UIImageView *image;
     IBOutlet UILabel *price;
     IBOutlet UILabel *description;

}

@property (nonatomic, retain)IBOutlet UIImageView *image;

@property (nonatomic, retain)IBOutlet UILabel *price;

@property (nonatomic, retain)IBOutlet UILabel *description;


@end


推荐答案

在实际实例化视图控制器的视图之前,您的插件将不会被设置,在您的情况下可能很快就会发生 <$ em> <$ em $ c> c> initWithNibName:bundle: - 哪一点他们仍然是零。任何涉及这些插座的设置都应该在视图控制器的 -viewDidLoad 方法中进行。

Your outlets won't get set until the view controller's view is actually instantiated, which in your case is probably happening shortly after initWithNibName:bundle:—at which point they'll still be nil. Any setup you do that involves those outlets should be happening in your view controller's -viewDidLoad method.

这篇关于UIViewController IBOutlets是零的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆