How to dismiss popover view on button click in iPad

Discussion in 'iOS Programming' started by Narendar Singh, Feb 4, 2013.

  1. Narendar Singh
    Expand Collapse
    macrumors member

    Narendar Singh

    Joined:
    Jun 22, 2012
    Location:
    INDIA
    #1
    Hi,

    I have a ViewController1 which has one button named "show".

    When I click on "show" it displays ViewController2 as popover.

    ViewController2 has a button "Close".

    What I want, when I click on "Close" button from ViewController2 it should be dismissed/disappear.

    Note: When I click on any other place on the screen ViewController2 disappears, and this is ok.
     
  2. robbieduncan
    Expand Collapse
    Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #2
    ViewController2 will need access to the UIPopoverController and call dismissPopoverAnimated:
     
  3. waterskier2007
    Expand Collapse
    macrumors 68000

    waterskier2007

    Joined:
    Jun 19, 2007
    Location:
    White Lake, MI
    #3
    You need to keep an instance variable of that popover controller in your main view controller. You should then set the main view controller as a delegate of your popover, and in your popover have the button push send a delegate method that tells the mainviewcontroller to use the method of the popover instance dismissPopoverAnimated:
     
  4. Narendar Singh
    Expand Collapse
    thread starter macrumors member

    Narendar Singh

    Joined:
    Jun 22, 2012
    Location:
    INDIA
    #4
    Working fine after following your suggested approach :)

    Thanks
     

Share This Page