iphone - UIPopover 委托(delegate) - 无论协议(protocol)/声明如何都无法分配

标签 iphone objective-c ios delegates uipopovercontroller

当我尝试为 UIPopoverView 分配委托(delegate)时,我很难弄清楚我做错了什么。我试图解决这个问题,甚至不使用它,但拥有它会更加简单和干净。这是我认为应该涵盖它的代码:

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

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

谢谢!

最佳答案

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

content.delegate = self;

在这行之后你有:

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

关于iphone - UIPopover 委托(delegate) - 无论协议(protocol)/声明如何都无法分配,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7418852/

相关文章:

iphone - 在 Objective C 中写入 TCP 套接字时出现问题(错误消息)

ios - TabBarController -> NavigationController -> 使用 Storyboard 的多个 UIViewController( Root View Controller )

iphone - 是否可以将 NSMutableArray 转换为 iPhone 中的相反顺序?

ios - 在if语句中定义'Cell'的实例-Swift

iPhone 开发 - 内存管理类(class)

xhtml - 在 iPhone 上使用 HTML 文件输入上传文件

objective-c - 可变数组中的 NSNumber=0

objective-c - 可以在同一个属性声明中同时使用strong和retain吗?

ios - 如何使用 Swift 获取一天中的小时数?

ios - 在 TableView 中重新加载数据