简体   繁体   English

UIPopoverController:关闭后更新视图

[英]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. 在iPad模拟器上,我有一个ViewController A,它呈现一个UIPopoverController,其contentViewController是ViewController B,在其中,我有一个按钮可以关闭UIPopoverController。

When it is dismissed, I need to update the view of ViewController A based on some field in ViewController B. 当关闭它时,我需要基于ViewController B中的某些字段来更新ViewController A的视图。

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: 为了做到这一点,我将ViewController A声明为ViewController B的一个属性( weakref ),以便在ViewController B中消除弹出窗口的位置,我可以说:

[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. 我认为,委托或发送NSNotification会更好。

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 最好的方法是使用Delegation ,就像在控制器B中声明委托一样

@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 在控制器A中,您可以处理此委托调用

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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