2011-03-29 4 views
0

다른보기에서 popover이라는 UIPopoverController이 있습니다. 내가 알고 싶은 것은, 현재 popover view에서 UIButton을 눌렀다면 popover를 취소 할 수 있습니까? 미리 감사드립니다.다른보기에서 UIPopoverController 닫기

답변

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

+0

몇 가지 예제 코드를 추가했습니다. 궁금한 점이 있으면 알려주세요. – FreeAsInBeer

+0

@Downvoter 왜 downvote? – FreeAsInBeer

2

나는 항상 이상하게 UIViewController에 그것이 "contentSizeForViewInPopover"속성,하지만 UIPopoverController 자체에 대한 포인터를 유지하지 않습니다 통해이 팝 오버에 있어야 얼마나 큰 알고 있다는 것을 발견했다. 항상 추가 끝내기 :

@property (nonatomic,assign) UIPopoverController* popover; 

내 UIViewController 클래스에 만들고 popover를 만들 때 설정합니다. 그런 다음 해당 UIViewController 아무것도에서 팝업을 닫으려면이 작업을 수행 할 수 있습니다.

[popover dismissPopoverAnimated:YES];