Search code examples
iphoneiosobjective-cuipopovercontrolleruistoryboard

Creating popover view controllers for Iphone in Interface Builder


How do I go about doing this? I know I have to give the popover a view controller that it constructs its view from, but I don't know how to construct this view in Interface Builder (like adding the labels and buttons and whatnot).

Do I just do it in the normal storyboard and have a storyboard that's randomly not connected to anything else, sitting off in the corner?

Do I create another storyboard?

Do I create a xib even though my project is all storyboard?

Do I create it programatically?


Solution

  • Since You did not specified target device in your question, I gave you Ipad answer

    IPAD:

    Go to your storyboard drag and drop a viewcontroller or tableviewcontroller its up to you. Then create a segue from desired viewcontroller on your storyboard to newly dragged/dropped viewcontroller. Choose your segue as popOver.

    enter image description here

    enter image description here

    Make sure you choose an anchor in segue settings like above picture. Then you need to edit size of your popover . If its a uiviewcontroller choose its view,if its a tableviewcontroller choose its tableview on left side of interface builder and edit its size.

    First:

    enter image description here

    Second:

    enter image description here

    After that customize your popover view controller (dragged/dropped view controller) add button,label whatever you want.

    If you are going to do additional things in your popover: Dont forget to create new file -> subclass of uiviewcontroller or uitableviewcontroller. Then associate it with your newly created viewcontroller on storyboard.

    enter image description here

    IPHONE:

    There are no Popover controllers in iphone

    But you try to use a third party https://github.com/50pixels/FPPopover solution that mimics popover behaviors in iphone by using QuartzCore

    I would try following:

    First:

    Again drag and drop a uiviewcontoller to your storyboard, then create a new file-> subclass of uiviewcontroller .

    This new uiviewcontroller will sit in the corner in your storyboard

    Then associate your uiviewcontroller in your storyboard with new Created file , lets say you created a new file name with YourViewController . Give your view a storyboard id and choose its class name.

    enter image description here

    -(IBAction)buttonClicked:(UIButton*)okButton
    {
        //the view controller you want to present as popover
        YourViewController *controller = [[YourViewController alloc] init]; 
    
        //if [[YourViewController alloc] init]; doesn't work try this
       // UIStoryboard* sb = [UIStoryboard storyboardWithName:@"MainStoryboard"
                                                         bundle:nil];
        //YourViewController *controller = [sb instantiateViewControllerWithIdentifier:@"YourViewController"]; 
    
        //our popover
        FPPopoverController *popover = [[FPPopoverController alloc] initWithViewController:controller]; 
    
        //the popover will be presented from the okButton view 
        [popover presentPopoverFromView:okButton]; 
    
        //no release (ARC enable)
        //[controller release];
    }
    

    Note: I havent used that FPPopover before so dont know how to arrange screen size but there must be further explanation in their documents just read it.