UIPopover 委托 - 无论协议/声明如何都无法分配
当我尝试为 UIPopoverView 分配委托时,我很难弄清楚我做错了什么。我试图解决这个问题,甚至不使用它,但拥有它会更加简单和干净。这是我认为应该涵盖它的代码:
//.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
我认为这就是我所需要的,但如果需要更多代码,请告诉我!
谢谢!
I'm having some difficulty figure out what I'm doing wrong when trying to assign my a delegate for my UIPopoverView. I tried to work around not even using one, but having it would be much more straightforward and clean. Here is the code that I think should cover it:
//.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
I think thats all I need, but let me know if more code is needed!
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我正确地理解了你......你需要的是:
在这一行之后你有:
I understood you correctly... what you need is:
Right after this line you have:
你正在综合你的属性吗?此外,您还要在启动弹出窗口之前分配委托...
@synthesize acTypePickerPopover;
self.acTypePickerPopover = [[[UIPopoverController 分配]
initWithContentViewController:_acTypePickerPopover] autorelease];
self.acTypePickerPopover.delegate = self;
`
Are you synthesizing your properties? Also you are assigning your delegate before initiating the popover...
@synthesize acTypePickerPopover;
self.acTypePickerPopover = [[[UIPopoverController alloc]
initWithContentViewController:_acTypePickerPopover] autorelease];
self.acTypePickerPopover.delegate = self;
`