2011-09-14 71 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中,它們不是同一件事。這是你想要做的嗎? –