我正在编写一个将在 iOS3.0 及更高版本上运行的应用程序。
该应用程序有一个自定义 UIViewController
(比如说),我从 .xib 文件实例化它。它的视图包含一个 UILabel
,我已在自定义 UIViewController
标头和实现文件中正确声明和合成了它。
我想动态设置此 UILabel
的文本,并在我的 UIViewController
出现时向用户显示。为了便于讨论,请假设文本设置方法的成本很高。
问题是在 iOS3.0 上,至少使用我的 UIViewController
,-(id)initWithNibName:(NSString *) aNibNameOrNil bundle:(NSBundle *) aNibBundleOrNil
在 之前返回-(void)viewDidLoad
确实如此,但在我的 iOS4.0 设备上却相反。因此,当我不希望文本标签为 nil 时,文本标签可以为 nil。
因此,我不知道在哪里可以设置文本以使iOS3.0和iOS4.0都满意。
这里有什么建议吗?
I'm writing an app that will run on iOS3.0 and up.
The app has a custom UIViewController
(say), which I'm instantiating from a .xib file. It's view comprises a single UILabel
, which I've correctly declared and synthesized etc. in my custom UIViewController
header and implementation files.
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. 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. The text label can therefore be nil
when I don't want it to be.
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.
Any advice here?
发布评论
评论(1)
您能解释一下您的标签是如何为零的吗?
如果您为标签选择了插座,那么无论哪种情况,在
- (void)viewDidLoad
方法中,只要标签插座在 xib 文件中正确连接,它就不能为 nil。如果您还没有使用标签出口并通过代码执行此操作,请在
- (void)viewDidLoad
方法中再次实例化标签,并在那里设置其文本,然后将其添加到视图控制器的视图中。有关更多信息 - 请阅读 - (void)viewDidLoad 和
- (id)initWithNibName:(NSString *)nibName bundle:(NSBundle *)nibBundle
方法="http://developer.apple.com/library/ios/#documentation/uikit/reference/UIViewController_Class/Reference/Reference.html" rel="nofollow">UIViewController 类参考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.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.For more information - read the
- (void)viewDidLoad
and- (id)initWithNibName:(NSString *)nibName bundle:(NSBundle *)nibBundle
method in the UIViewController class reference