开发者

IBOutlet not getting set outside didLoad

I have a view controller on which I have a text view.I am creating an object of this view controller in another class and in that class I am setting the text of the IBOutlet textView . Then I am pushing this view contoller object on my navigation controller.

But the text is not getting set.I debugged it and found that the object of text view is showing 0x0.If I set the text in didLoad then it gets set.Further,I tried first pushing the view and then calling the method to change the text but still it shows 0x0.

Can anyone let me let me know if I am doing something wrong??

LookUpReference *lookUp = [[LookUpReference alloc]init];
[self.navigationController pushViewController:lookUp animated:NO];
[lookUp loadViewWithResponse:开发者_JAVA技巧responseString];

method loadViewWithResponse:-

-(void) loadViewWithResponse:(NSString *)responseString
{
    txtViewDescription.text=responseString;
}


Viewcontrollers loads their view lazily. So when you set the property txtViewDescription.text = responseString; you are actually assigning the responseString to a variable which is nil. So if you want to do something like that you could e.g. make a new property however with type NSString and assign the value to this instance variable. and instead of assigning the responseString to the textview assign it to that variable and in your viewDidLoad or whatever selector you are using get the value from that.


The XIB file is loaded lazily, upon reference to the view ivar, so your txtViewDescription is null until then. Try to access the view member to cause the view controller to load it in.


As @DavidNeiss said you need to access the view. Try:

self.view = self.view; // Causes the view to load

This form will not cause any warnings.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜