4

I'd like to design my views quietly in Interface Builder, then to be able to display them dynamically as an UIPopoverController.

I found this precious tutorial by Ray Wenderlich but I cannot extend it to my needs.

Anyone could help me?

Luuklag
  • 3,897
  • 11
  • 38
  • 57
gluon
  • 662
  • 1
  • 10
  • 18
  • What exactly is your problem? Making UIViewControllers and present them as popovers is very easy and should be covered in that tutorial. What's the part that causes you trouble? Are you perhaps trying to present views not attached to a view controller? – BBog May 03 '12 at 12:09
  • Hi Bogdan, I have a view attached to a view controller. I don't know how to display it as a popover using this code. Indeed, in the tutorial, Ray builds a table view controller. – gluon May 03 '12 at 15:57

1 Answers1

7

Here is how I usually do it: let's say I have a parent view controller in which I want to present the popover. I declare a popover controller as a property for that VC ( @property (nonatomic, retain) UIPopoverController* popOverController; )

The code for presenting a popover with a new view controller, let's call it ViewController2, would be this one

ViewController2* viewController2 = [[ViewController2 alloc] initWithNibName:@"ViewController2"  bundle:nil];

self.popOverController = [[UIPopoverController alloc] initWithContentViewController:viewController2];

popOverController.popoverContentSize = CGSizeMake(350, 216); //or whatever size you need

//this will present the view controller from the sender's frame, assuming this code is used inside an IBAction 
//and the popover's arrow will point down
[popOverController presentPopoverFromRect:[sender frame] inView:self.view  permittedArrowDirections:UIPopoverArrowDirectionDown animated:YES]; 

[viewController2 release];

[popOverController release];

That's pretty much it... If you run into any problems, I'll try to give you more infos.

P.S. I am not claiming this is the best way to do it, I have less than an year of experience with iOs, but that's how we usually do it where I work

BBog
  • 3,630
  • 5
  • 33
  • 64
  • It totally answers and I also understood everything. Thanks a lot Bogdan! You can check my project(S) on my blog if you are interested http://julienbayle.net – gluon May 04 '12 at 21:23
  • I tested, it works. BUT, in the VC2.mm file, in the IBAction related to some UI elements (sliders etc), when I modify a value, I have a strange crashs EXEC_BAD_ACCESS related to the final target controller... digging.. The fact I allocate & release the popover & VC 2 in the same IBAction is ok right. ..? – gluon May 04 '12 at 22:09
  • Yes, it's ok. What do the crash logs tell you about the error? Also, try to enable NSZombies, this usually helps a lot when dealing with EXEC_BAD_ACCESS errors http://stackoverflow.com/q/5386160/855738 – BBog May 07 '12 at 06:39
  • Thanks a lot Bogdan. Using OpenFrameworks as the core (and the first delegate), I had to not invoke methods from the popover content directly: the popover content methods are wrapped to the same methods in the parent view controller and those last are calling method to OF. Strange. Probably not the best, but working fine. Thanks for your comment on my blog too :) – gluon May 07 '12 at 07:12