开发者

Popover view notification

I have a pop over view开发者_JAVA技巧. When this popover gets dismissed, I want to get notified.

Is there any way to do it?


The answer is incredibly simple!

The delegate routine popoverControllerDidDismissPopover is called for you whenever the popover is dismissed.

So just add this code to your code...

-(void)popoverControllerDidDismissPopover:
        (UIPopoverController *)popoverController
    {
    NSLog(@"a popover was dismissed! thank you stackoverflow!");
    }

OK? You can also use popoverControllerShouldDismissPopover if you actually want to prevent it from being dismissed.

(Note - in the unusual case you are working with more than one popover, just check inside that routine which one it is that is being dismissed. So something like popoverController == myPostcodePopover or whatever.)

If you don't know how to do something, the solution is almost always in the delegates available with the class you are working with.

----------- don't forget to do this!

Whenever you use any delegate, of course you have to set the delegate to be "you",

zipcodeEntryPopover.delegate = self;

----------- don't forget to do this!

If you're going to use a delegate like that, you just need to add it to your delegate declarations where you declare the class in your .h file.

So, in your .h file you will have something like this,

@interface yourHappyThing : UIViewController <ASIHTTPRequestDelegate,
                    UIAccelerometerDelegate,
                    thisDelegate,
                    thatDelegate>

(Often you have a large number of them in there, both system delegates and your own which you have created.) So, you just need to add the one for the popover delegate, thus ...

@interface yourHappyThing : UIViewController <ASIHTTPRequestDelegate,
                    UIAccelerometerDelegate,
                    thisDelegate,
                    thatDelegate,
                    UIPopoverControllerDelegate>

That should do it!


Like the others have said, use -(void)popoverControllerDidDismissPopover: (UIPopoverController *)popoverController But they all missed one critical point; don't forget to change the delegate of the UIPopoverController when you create it:

UIPopoverController *popoverController = [[UIPopoverController alloc] initWithContentViewController:datePicker];
popoverController.delegate = self;


use this delegate method

-(void)popoverControllerDidDismissPopover:
    (UIPopoverController *)popoverController
{

}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜