从另一个视图中关闭UIPopoverController

时间:2011-03-29 16:35:54

标签: objective-c cocoa-touch ios uipopovercontroller

我在另一个视图中有一个名为UIPopoverController的{​​{1}}。我想知道的是,如果在当前的弹出视图中按下popover,我如何解除弹出窗口?提前谢谢。

2 个答案:

答案 0 :(得分:2)

我总是觉得奇怪的是,UIViewController通过它的“contentSizeForViewInPopover”属性知道弹出窗口应该有多大,但是没有保留指向UIPopoverController本身的指针。我总是最后添加:

@property (nonatomic,assign) UIPopoverController* popover;

到我的UIViewController类,并在创建弹出窗口时设置它。然后从UIViewController中的任何东西,我可以这样做来解除popover:

[popover dismissPopoverAnimated:YES];

答案 1 :(得分:1)

您可以使用NSNotification告诉其他视图忽略它的弹出视图。

使用示例:

// Add an observer that will respond to our notification.
[[NSNotificationCenter defaultCenter] addObserver:self // <- This is the object that will has the selector that we want to run (the same one we use in the next line).
                                         selector:@selector(doSomething:) // <- This is the selector we want to run.
                                             name:@"doSomethingNow" // <- This is notification name we will send to activate our observer's selector.
                                           object:nil]; // Don't worry about this for now.


// Post the notification. This has the same name as our observer above, so our 'doSomething' selector should be run.
[[NSNotificationCenter defaultCenter] postNotificationName:@"doSomethingNow" object:nil];


// the function specified in the same class where we defined the addObserver
- (void)doSomething:(NSNotification *)pNotification {
    NSLog(@"Received Notification..."); 
}