0

I am using UAModalPanel to create a popover controller effect. I can get the popver box to display, but I am struggling to figure out how to create a view (graphically, in storyboard), instantiate that view in code, and add it to the UAModalPanel.

What I've Tried

  • Created a UIViewController in storyboard, set it's class to a custom class, instantiated that class in code, got it's view and tried to add it to the current 'scene'.

That's it. Surely there is a way that I can make a view in storyboard, have it make a sub-class of UIView which I can then grab in code where I need to use it? Instead of laying it out in code?

2 Answers 2

2

In storyboards you'll want to drag and drop a new UIViewController then give it an identifier here:

enter image description here

Then in code you can get the view property of this view controller with the following:

UIViewController *myController = [self.storyboard instantiateViewControllerWithIdentifier:@"myIDfromTheLastStep"];

Now you can get the conrollers view property and make adjustments. Here's an example of frame change

[myController.view setFrame:CGRectMake(0, 0, 320, 320)];
Sign up to request clarification or add additional context in comments.

Comments

1

Unless you need the segues you may better off creating a standalone XIB

Layout the view as you need, set its Class to your own (MyCustomView) then instantiate like this

 NSArray *nib=[[NSBundle mainBundle] loadNibNamed:@"MyCustomView" owner:self options:nil];
 MyCustomView *view = (MyCustomView*)[nib objectAtIndex:0];

As long as your view is the first/only object in the XIB this will instantiate the view for you

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.