[英]iOS3, iOS4, xibbed UIViewController and displaying data
I'm writing an app that will run on iOS3.0 and up. 我正在编写一个将在iOS3.0及更高版本上运行的应用程序。
The app has a custom UIViewController
(say), which I'm instantiating from a .xib file. 该应用程序有一个自定义
UIViewController
(例如),我是从.xib文件实例化的。 It's view comprises a single UILabel
, which I've correctly declared and synthesized etc. in my custom UIViewController
header and implementation files. 它的视图包含一个
UILabel
,我已经在我的自定义UIViewController
标头和实现文件中正确声明和合成了类似内容。
I'd like to set the text of this UILabel
dynamically, and for it to be shown to the user by the time my UIViewController
appears. 我想动态设置此
UILabel
的文本,并在UIViewController
出现时将其显示给用户。 For sake of argument please assume the text setting method is expensive. 为了便于讨论,请假设文本设置方法昂贵。
The catch is on iOS3.0 with my UIViewController
at least, -(id)initWithNibName:(NSString *) aNibNameOrNil bundle:(NSBundle *) aNibBundleOrNil
returns before -(void)viewDidLoad
does, but on my iOS4.0 device it's the other way around. 在iOS3.0上,我的
UIViewController
至少是个问题, -(id)initWithNibName:(NSString *) aNibNameOrNil bundle:(NSBundle *) aNibBundleOrNil
在-(void)viewDidLoad
之前返回,但是在我的iOS4.0设备上是另一个的方式。 The text label can therefore be nil
when I don't want it to be. 因此,当我不希望使用文本标签时,它可以为
nil
。
Thus, I don't know where I can set the text in such a way as to keep both iOS3.0 and iOS4.0 happy. 因此,我不知道在哪里可以设置文本以保持iOS3.0和iOS4.0都满意。
Any advice here? 有什么建议吗?
Can you please explain how your label comes out to be nil? 您能解释一下您的标签是如何变成零的吗?
If you have taken an outlet for the label, then in either case, in the - (void)viewDidLoad
method it cannot be nil, provided the label outlet is properly connected in the xib file. 如果为标签取了一个插座,则无论哪种情况,在
- (void)viewDidLoad
方法中,只要在xib文件中正确连接了标签插座,就不能为nil。
If you have not taken the label outlet and doing it by code, then instantiate the label again in - (void)viewDidLoad
method and set its text right over there and then add it to the view controller's view. 如果您尚未取出标签出口并通过代码进行处理,请在
- (void)viewDidLoad
方法中再次实例化标签,并在该位置设置其文本,然后将其添加到视图控制器的视图中。
For more information - read the - (void)viewDidLoad
and - (id)initWithNibName:(NSString *)nibName bundle:(NSBundle *)nibBundle
method in the UIViewController class reference 有关更多信息-请阅读UIViewController类参考中的
- (void)viewDidLoad
和- (id)initWithNibName:(NSString *)nibName bundle:(NSBundle *)nibBundle
方法
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.