2

In my iOS application I try to present new ViewController "above" current one. Following this Apple guideline, in some event I use the following code:

MyViewController* vc = [[MyViewController alloc] initWithNibName: nil bundle: nil];
vc.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;

UINavigationController* nc = [[UINavigationController alloc]  initWithRootViewController: vc];
[mainController presentViewController:nc animated:YES completion:nil];

This code is called (and it happens after main controller is successfully loaded, not within viewDidLoad) and new view appears using chosen transition style.
MyViewController class is created, and its methods like viewDidLoad and supportedInterfaceOrientations are successfully called.

Now here goes the problem.
In interface builder I create controller, setting its class to MyViewController. I create a number of views inside this controller, UIButton, for example. MyViewController has the property

IBOutlet UIButton* button

On storyboard, referencing outlet of placed UIButton is set to "button" property of the controller. As a double-check, in "Outlets" section of the view controller on storyboard "button" is bound to the placed UIButton object.

But when viewDidLoad is called, value of button property is nil. Naturally, button doesn't display. The same goes for two UITableView objects (they dataSource and delegate are both set to the same view controller and MyViewController conforms

<UITableViewDelegate, UITableViewDataSource> 

in case it's important).

In addition, black screen that appears ignores all touches (and swipe gesture recognizer is placed on the controller on storyboard). But it reacts on orientation changes.
I suppose the problem is that created instance of MyViewController fails to "see" the storyboard and I miss something very basic, but I see no hints in Apple documentation.

Abstraction
  • 1,108
  • 11
  • 25

1 Answers1

3

You are initializing MyViewController in a wrong way. Because you are using "Storyboard" you should give view an Identifier Name (in storyboard) and then initialize your controller from storyboard.

    MyViewController* vc = [self.storyboard instantiateViewControllerWithIdentifier:@"MyViewControllerIdentifier"];
tadasz
  • 4,366
  • 5
  • 26
  • 33
  • Thank you. This works just fine. On a side note, if someone has the same problem and after fixing it gets a problem with cell identifiers in table view, be sure to check [this post](http://stackoverflow.com/questions/12737860/assertion-failure-in-dequeuereusablecellwithidentifierforindexpath) as well. – Abstraction Jul 23 '13 at 09:29