Reputation: 34830
I am trying to present a UIViewController
inside a UIPopoverController
. I've designed a view controller in Interface Builder, gave it a custom class (let's say MyAppTestViewController
) and I'm trying to create a popover this way:
MyAppTestViewController *fxViewController = [MyAppTestViewController new];
self.fxPopover = [[UIPopoverController alloc] initWithContentViewController:fxViewController];
self.fxPopover.popoverContentSize = CGSizeMake(1024, 120);
[self.fxPopover presentPopoverFromBarButtonItem:_fxButton permittedArrowDirections:UIPopoverArrowDirectionDown animated:NO];
When I press the button, a popover is displayed at the correct place with the correct size, but it is empty. I've verified that the MyAppTestViewController
's viewDidAppear
method is being called (by NSLog
), but the Popover's inside is empty:
Am I missing something?
Upvotes: 2
Views: 1819
Reputation: 1913
I see that you mentioned in a comment that you're using a storyboard. So why not use a popover segue to your MyAppTestViewController
? You could wire the segue directly to the Effects button on your toolbar. (Or, alternatively, call performSegueWithIdentifier:
from your presenting view controller.) You might do a quick test by just throwing a UILabel into MyAppTestViewController
right on the storyboard and seeing if it displays properly.
Upvotes: 2
Reputation: 9297
I think the problem is here:
MyAppTestViewController *fxViewController = [MyAppTestViewController new];
Generally you would use [[MyViewControllerClass alloc] initWithNibName:nil bundle:nil]
(assuming you have a xib file with a matching name). I don't believe I have ever seen a view controller initialized with new
. Everything in Objective-C is alloc-init.
Apple Docs: UIViewController Class Reference
Quote:
To initialize your view controller object using a nib, you use the initWithNibName:bundle: method to specify the nib file used by the view controller. Then, when the view controller needs to load its views, it automatically creates and configures the views using the information stored in the nib file.
EDIT:
Fascinating, well okay. It looks like you are right about the use of the new keyword, here is bit of an explanation of this.
So fine, that's not the problem. Have you tried breaking on the viewDidAppear
method and using the debugger to print out the view properties, check its frame, check its superview, and so on, try to understand the problem better? You may already know how to do this, but the commands would be po self.view
and so on.
In any case, I also found this, although it only goes into the mechanics of popover presentation and not content view assignment, which you seem to have down.
Upvotes: 1