简体   繁体   中英

UIPopoverController: update view after it is dismissed

On iPad simulator, I have a ViewController A that presents an UIPopoverController whose contentViewController is ViewController B, inside which I have a button to dismiss the UIPopoverController.

When it is dismissed, I need to update the view of ViewController A based on some field in ViewController B.

In order to do this, I am declaring ViewController A as a property ( weakref ) of ViewController B so that within ViewController B where it dismisses the popover, I can say:

[self.viewControllerA.popover dismissPopoverAnimated:YES];
self.viewControllerA.popover = nil;
self.viewControllerA.textLabel.text = self.someField

Is this the correct way of doing it? Since there is no callback when we dismiss the popover pragmatically, I can't think of any better solution.

Anybody has a better idea? Passing view controllers around just seems awkward to me.

I think, delegates or sending NSNotification will make better.

Note:

A change of the execution sequence will do more perfection to your current code.

self.viewControllerA.textLabel.text = self.someField
[self.viewControllerA.popover dismissPopoverAnimated:YES];
self.viewControllerA.popover = nil;

The best way is use of Delegation , just declare the delegate in your controller B like

@protocol ControllerSDelegate <NSObject>
-(void) hidePopoverDelegateMethod;
@end

and call this on action for passing the data and dismiss of controller like

if (_delegate != nil) {
    [_delegate hidePopoverDelegateMethod];
}

and

in your controller A you can handle this delegate call

-(void) hidePopoverDelegateMethod {
    [self.paymentPopover dismissPopoverAnimated:YES];
    if (self.paymentPopover) {
        self.paymentPopover = nil;
    }
    [self initializeData];
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM