Reputation: 33644
So I am pretty new to this story board concept. I have a view nibs dropped in to the storyboard and each corresponding to a UIViewController subclass I have, I tried loading the nib file using the following code:
TestViewController *vc = [[TestViewController alloc] initWithNibName:@"TestViewController" bundle:nil];
[self.view setBackgroundColor:[UIColor blueColor]];
[self.view setFrame:CGRectMake(0, self.profilePicture_.frameHeight + self.profilePicture_.frameY + 10, self.scrollView_.frameWidth, 100)];
[self.view addSubview:vc.view];
However, it gives me the following error:
*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Could not load NIB in bundle: 'NSBundle </Users/aditya15417/Library/Application Support/iPhone Simulator/5.1/Applications/64E6CEC9-E6DC-4AF5-BF16-11BFB6415BDC/Pulse.app> (loaded)' with name 'TestViewController''
So the question is, if I have my nib in the story board is it not possible to use the initWithNibName? If there is a way, how do I do this?
Upvotes: 3
Views: 5665
Reputation: 21
This is the way I'd do it:
UIStoryboard *storyBoard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:[NSBundle mainBundle]];
Upvotes: 0
Reputation: 2336
Please use
[self.storyboard instantiateViewControllerWithIdentifier:@"some identifier you set in IB"];
Upvotes: 7
Reputation: 126107
When you use a storyboard, you don't use individual nibs directly, and you don't instantiate view controllers yourself. You can use the UIStoryboard
class to instantiate a view controller from the storyboard as described in the documentation.
Upvotes: 0
Reputation: 1118
Why are you loading PNRNewsfeedViewController as TestViewController? Is TestViewController the base class for PNRNewsfeedViewController? Make sure that in the nib, the File's Owner custom class is set to PNRNewsfeedViewController, and then allocate a news feed view controller:
PNRNewsfeedViewController *vc = [[PNRNewsfeedViewController alloc] initWithNibName:@"PNRNewsfeedViewController" bundle:nil];
// ...
Upvotes: 0