UIPopover 委托 - 无论协议/声明如何都无法分配

发布于 2024-12-05 03:17:58 字数 1818 浏览 6 评论 0原文

当我尝试为 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

皇甫轩 2024-12-12 03:17:58

我正确地理解了你......你需要的是:

content.delegate = self;

在这一行之后你有:

ACTypePopoverViewController* content = [[ACTypePopoverViewController alloc] init];

I understood you correctly... what you need is:

content.delegate = self;

Right after this line you have:

ACTypePopoverViewController* content = [[ACTypePopoverViewController alloc] init];
茶花眉 2024-12-12 03:17:58

你正在综合你的属性吗?此外,您还要在启动弹出窗口之前分配委托...

@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;
`

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文