UIViewController IBOutlets 为零
我有一个带有两个标签的 UIViewController 类和一个设置为 IBOutlets 的 UIImageView,并且我在我的 xib 中连接了这个插座,我已经仔细检查它们是否正确连接,但是当我在调试器中检查它们的值时,它们是 0x0 所以我不能以编程方式更改它们。关于我可能做错了什么的任何想法。
这是我的代码的头文件:
#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
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在视图控制器的视图实际实例化之前,您的插座不会被设置,在您的情况下,这可能发生在
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.