当我尝试为 UIPopoverView 分配委托(delegate)时,我很难弄清楚我做错了什么。我试图解决这个问题,甚至不使用它,但拥有它会更加简单和干净。这是我认为应该涵盖它的代码:
//.h of View where I call popover, this would be the delegate.
#import <UIKit/UIKit.h>
#import "ACTypePopoverViewController.h"
@interface NewRouteViewController : UIViewController<ACTypePickerDelegate>{
ACTypePopoverViewController *_acTypePicker;
UIPopoverController *_acTypePickerPopover;
}
@property (nonatomic, retain) ACTypePopoverViewController *acTypePicker;
@property (nonatomic, retain) UIPopoverController *acTypePickerPopover;
@end
//.m file for where I would like to use the popover, is the .m for the .h above
if (_acTypePickerPopover == nil)
{
ACTypePopoverViewController* content = [[ACTypePopoverViewController alloc] init];
UIPopoverController* aPopover = [[UIPopoverController alloc]
initWithContentViewController:content];
aPopover.delegate = self;
[content release];
// Store the popover in a custom property for later use.
self.acTypePickerPopover = aPopover;
}
[self.acTypePickerPopover presentPopoverFromRect:self.selectACTypeButton.frame inView:self.view permittedArrowDirections:UIPopoverArrowDirectionLeft animated:YES];
//.h file for the actual popover, what I would be setting the delegate of
@protocol ACTypePickerDelegate
- (void)acTypeSelected:(NSString *)acType;
@end
@interface ACTypePopoverViewController : UITableViewController {
NSMutableArray *_acTypes;
NSString *selectedACType;
id<ACTypePickerDelegate> _delegate;
}
@property (nonatomic, retain) NSMutableArray *acTypes;
@property (nonatomic, retain) NSString *selectedACType;
@property (nonatomic, assign) id<ACTypePickerDelegate> delegate;
@end
我认为这就是我所需要的,但如果需要更多代码,请告诉我!
谢谢!
最佳答案
我理解你的意思是正确的......你需要的是:
content.delegate = self;
在这行之后你有:
ACTypePopoverViewController* content = [[ACTypePopoverViewController alloc] init];
关于iphone - UIPopover 委托(delegate) - 无论协议(protocol)/声明如何都无法分配,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7418852/