UIPopoverController Delegate Problem?
I have a UIPopover that I want to use either
-(BOOL)popoverControllerShouldDismissPopover:(UIPopoverController *)popoverController{
return NO;
}
or
-(void)popoverControllerDidDismissPopover:(UIPopoverController *)popoverController{}
on. Neither of them seem to work (and I'm sure once one is fixed, the other will be too since it's probably a problem with delegates). For delegates, here is what I have:
In optionsViewController.h, the view which is inside the popover:
#import <UIKit/UIKit.h>
@protocol OptionsViewControllerDelegate <NSObject>
-(void)didPick:(NSString *)string;
@end
id delegate;
@interface OptionsViewController : UIViewController <OptionsViewCon开发者_JAVA百科trollerDelegate>{
IBOutlet UIPickerView *picker;
NSMutableArray *list;
}
@property (nonatomic, copy) NSArray *passthroughViews;
@property(nonatomic,retain) NSMutableArray *list;
@property(nonatomic,assign) id<OptionsViewControllerDelegate> delegate;
@end
and in the .m:
@synthesize delegate;
and in the .h of the view where the popover appears:
@interface exampleViewController : UIViewController <OptionsViewControllerDelegate,UIPopoverControllerDelegate>{
UIPopoverController *popoverController;
OptionsViewController *optionsViewController;
}
and in the .m:
@synthesize popoverController;
@synthesize optionsViewController;
-(BOOL)popoverControllerShouldDismissPopover:(UIPopoverController *)popoverController{
return NO;
}
[popoverController release];
[optionsViewController release];
In the ViewDidLoad, I have:
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
optionsViewController =[[OptionsViewController alloc]init];
optionsViewController.delegate = self;
popoverController = [[UIPopoverController alloc] initWithContentViewController:optionsViewController];
popoverController.popoverContentSize = CGSizeMake(320, 216);
}
To present the popover, I use:
-(IBAction)showDecadePopover{
[popoverController presentPopoverFromRect:CGRectMake(150, 50, 150, 50) inView:self.view permittedArrowDirections:UIPopoverArrowDirectionLeft animated:YES];
}
I'm probably missing something really obvious (that's why I gave so much of my code). Thanks so much!
Luke
Yep, simple fix. After you init the popoverController you need to set the exampleViewController as the delegate of it.
[popoverController setDelegate:self];
PS: What is the id delegate;
floating after your OptionsViewControllerDelegate protocol definition for? Synthesizing delegate
, which you already do, is all you need to create storage for it.
精彩评论