2011-09-14 44 views
0

我有一些困难找出我做错了什么时试图为我的UIPopoverView分配我的委托。我试图解决甚至不使用一个,但它会更直接和干净。下面是我认为应该包括它的代码:UIPopover委托 - 无法分配,无论协议/声明

//.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 

我想这就是我所需要的,但让我知道,如果需要更多的代码!

谢谢!

回答

1

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

content.delegate = self; 

权在此行之后您有:

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

这使得一个很大的意义,当然它现在工作。谢谢! –

0

你在综合你的房产吗?另外你正在发起的酥料饼之前分​​配您的代理...

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

+0

哎呀!我正在玩弄它,我想我后来就搞砸了。我加入了调试器,并且当我实际分配委托时,该值是正确的,但是当我从弹出窗口访问委托时,它不再具有任何价值,对此有何想法? –

+0

你说你试图从popover访问委托。你最近怎么样?您将无法从您的UITableViewController访问它 - UITableViewController位于UIPopOverController中,它们不是同一件事。这是你想要做的吗? –