0

I have main viewcontroller that opens via popover segue other view controller with buttons. On button click what I wish to happen is function from first viewcontroller fire and the popover will close. How do I do so properly?

enter image description here

On settings button click the popover open. Then when user click Manual Content Update the the view will close and start function on Projects Main viewController.

Dim
  • 3,529
  • 10
  • 67
  • 119
  • You can use unwind segues to do that. See http://stackoverflow.com/questions/12561735/what-are-unwind-segues-for-and-how-do-you-use-them – Felix Dec 07 '14 at 08:49
  • One solution is to use `NSNotificationCenter` http://stackoverflow.com/questions/2191594/send-and-receive-messages-through-nsnotificationcenter-in-objective-c – user623396 Dec 07 '14 at 09:18

1 Answers1

1

You can use NSNotificationCenter.

In your main UIViewController add:

- (void)viewDidLoad {
    [super viewDidLoad];

[[NSNotificationCenter defaultCenter] addObserver:self
        selector:@selector(receivePopoverNotification:) 
        name:@"PopoverNotification"
        object:nil];
}

-(void) dealloc{
        [[NSNotificationCenter defaultCenter] removeObserver:self];    
}

- (void) receivePopoverNotification:(NSNotification *) notification
{
    [self.popover dismissPopoverAnimated: YES];
    self.popover = nil;
}

In your UIPopoverController add:

-(IBAction) pressButton: (id) sender {
     [[NSNotificationCenter defaultCenter] 
        postNotificationName:@"PopoverNotification" 
        object:nil];
}
alerojlop
  • 41
  • 5