azh3qg
Last Updated: February 25, 2016
·
1.821K
· adamyanalunas

Testing nibs (Kiwi, OCUnit, KIF, whatevs)

Sometimes you forget the steps Cocoa/CocoaTouch does for you when instantiating a (NS|UI)ViewController.

If you're doing some programmatic testing of your view controllers and need to know that something in the nib loaded correctly you need to do two things:

UIViewController *myVC = [myVC.alloc initWithNib:@"nibFileName" bundle:nil];
[myVC loadView];

That's it. Now your nib will be unpacked and all elements initialized into its .view. Carry on doing fun things like [myVC.inputField.text shouldBeNil].

Say Thanks
Respond

3 Responses
Add your response

5493
35afc3a

+1 The documentation begins with "You should never call this method directly."

over 1 year ago ·
11503
2d122d90922fc6d735e40e348a669747

instead of [myVC loadView]; use;

UIView *v = myVC.view

UIViewController.view is lazy loaded; as soon we access it, it will create the view.

over 1 year ago ·
11504

@johnhatvani Nice tip. Thanks!

over 1 year ago ·