我正在尝试添加自定义元素,包括从我的 navigationBar
更改的下拉菜单和 View ,因此我需要一个自定义元素。但是,当尝试将委托(delegate)设置为我的 View Controller 时,它会引发错误。
@interface MyViewController : UIViewController <MyCustomNavigationBarDelegate>
@implementation MyViewController
- (void)viewDidLoad {
[super viewDidLoad];
UINavigationController *nav = [[UINavigationController alloc] initWithNavigationBarClass:[MyCustomNavigationBar class] toolbarClass:[UIToolbar class]];
nav.navigationBar.assessmentDelegate = self;
}
最后一行抛出错误 Property 'assesmentDelegate
' not found on object of type 'UINavigationBar
*' 但是它应该是类的类型 MyCustomNavigationBar
显然有委托(delegate):
@protocol MyCustomNavigationBarDelegate;
@interface MyCustomNavigationBar : UINavigationBar
@property (weak, nonatomic) id <MyCustomNavigationBarDelegate> assessmentDelegate;
@end
@protocol MyCustomNavigationBarDelegate <NSObject>
-(void)presentViewControllerUIAlertController *)alert;
@end
将您的导航栏转换到 MyCustoms 导航栏
MyCustomNavigationBar *switchNav = (MyCustomNavigationBar *)nav.navigationBar;
switchNav.assessmentDelegate = self
关于ios - 为自定义 UINavigationBar 设置委托(delegate),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37274218/
欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://jike.in/) | Powered by Discuz! X3.4 |