2011-03-29 75 views

回答

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..."); 
} 
+0

我可以得到一個示例代碼嗎? – ishhhh 2012-11-12 10:10:37

+0

我添加了一些示例代碼。如果您有任何問題,請告訴我。 – FreeAsInBeer 2012-11-12 14:23:54

+0

@Downvoter爲什麼downvote? – FreeAsInBeer 2013-12-27 14:14:05

2

我一直覺得很奇怪,一個UIViewController知道它應該有多大的酥料餅通過它的「contentSizeForViewInPopover」屬性,但指針不保留到UIPopoverController本身。我總是最後加入:

@property (nonatomic,assign) UIPopoverController* popover; 

我的UIViewController類,並設置,當創建popover。然後從該UIViewController中的任何東西,我可以這樣做來解僱popover:

[popover dismissPopoverAnimated:YES]; 
相關問題