Storyboard and popover views...

Discussion in 'iOS Programming' started by Ubuntu, Aug 29, 2012.

  1. macrumors 68000

    Joined:
    Jul 3, 2005
    Location:
    UK/US
    #1
    Hello,

    I've been quite happily finishing off my application, which uses storyboards and popover viewcontrollers. This all works fine, except I recently noticed that one can press the initiating button however many times they like and it'll create a new instance of the view controller each time.

    Before storyboards I worked a bit with popover views using a popovercontroller which seems to prevent this issue.

    Has anyone got any experience of how to fix this issue while still using Storyboards - and ideally not having to resort to the disabling and reenabling of buttons?

    Thanks
     
  2. macrumors 6502

    Joined:
    Jul 14, 2008
    #2
    Create a (private) property of type UIPopoverController. In prepareForSegue, do the following:

    Code:
    if ([segue isKindOfClass:[UIStoryboardPopoverSegue class]]) {
    		
    		if (self.popover.popoverVisible)
    			[self.popover dismissPopoverAnimated:NO]; // No animation needed; other UIPopover is taking over
    		
    		self.popover = [(UIStoryboardPopoverSegue *)segue popoverController];
    	}
    
    This basically dismisses any visible popover before it shows the new one.
     
  3. thread starter macrumors 68000

    Joined:
    Jul 3, 2005
    Location:
    UK/US
    #3
    That worked beautifully. Thanks.
     

Share This Page