开发者

Is it possible to programmatically set parent-child relationships in Objective-C code like an IB nib file does?

I'm trying to unit test some controller code in an iPhone application. The code I'm testing is relying on calling self.navigationController, which in my test is nil. In the actual application, the navigation controller gets set up by virtue of being a parent of my controller inside the nib file. I would love to be able to just set the navigation controller on my controller in my unit tests, but navigationController is a readonly property. Is there a way to programmatically set up the parent-child relation开发者_如何学编程ship in my test (just like the nib file does), so that the navigationController method will find it?


UIViewController *temp = [[UIViewController alloc]init];

UINavigationController *_temp = [[UINavigationController alloc]initWithRootViewController:temp];

Is this what you are looking for?

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜