Objective c 从另一个视图中关闭UIPopoverController

Objective c 从另一个视图中关闭UIPopoverController,objective-c,cocoa-touch,ios,uipopovercontroller,Objective C,Cocoa Touch,Ios,Uipopovercontroller,我在另一个视图中有一个名为popover的UIPopoverController。我想知道的是,如果在当前的popover视图中按下了ui按钮,如何取消popover?提前感谢。您可以使用通知另一个视图关闭其popover视图 用法示例: // Add an observer that will respond to our notification. [[NSNotificationCenter defaultCenter] addObserver:self // <- This is

我在另一个视图中有一个名为
popover
UIPopoverController
。我想知道的是,如果在当前的popover视图中按下了
ui按钮
,如何取消popover?提前感谢。

您可以使用通知另一个视图关闭其popover视图

用法示例:

// 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..."); 
}
//添加一个将响应我们通知的观察者。
[[NSNotificationCenter defaultCenter]addObserver:self/您可以使用通知另一个视图关闭其popover视图

用法示例:

// 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..."); 
}
//添加一个将响应我们通知的观察者。

[[NSNotificationCenter defaultCenter]addObserver:self/我总是觉得奇怪,UIViewController通过它的“contentSizeForViewInPopover”属性知道它在popover中应该有多大,但没有保留指向UIPopopOvercontroller本身的指针。我总是添加:

@property (nonatomic,assign) UIPopoverController* popover;
在创建popover时设置。然后,从该UIViewController中的任何内容,我可以执行以下操作来关闭popover:

[popover dismissPopoverAnimated:YES];

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

@property (nonatomic,assign) UIPopoverController* popover;
在创建popover时设置。然后,从该UIViewController中的任何内容,我可以执行以下操作来关闭popover:

[popover dismissPopoverAnimated:YES];

我添加了一些示例代码。如果您有任何问题,请告诉我。我添加了一些示例代码。如果您有任何问题,请告诉我。