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

时间:2011-09-14 15:22:07

标签: iphone objective-c ios delegates uipopovercontroller

在尝试为我的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

我认为这就是我所需要的,但如果需要更多代码,请告诉我们!

谢谢!

2 个答案:

答案 0 :(得分:1)

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

content.delegate = self;

在这一行之后你有:

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

答案 1 :(得分:0)

你在合成你的房产吗?你也在启动popover之前分配你的代表......

@synthesize acTypePickerPopover;
self.acTypePickerPopover = [[[UIPopoverController alloc] initWithContentViewController:_acTypePickerPopover] autorelease];
self.acTypePickerPopover.delegate = self; `