gpt4 book ai didi

ios - 为自定义 UINavigationBar 设置委托(delegate)

转载 作者:塔克拉玛干 更新时间:2023-11-02 21:06:14 26 4
gpt4 key购买 nike

我正在尝试从我的 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 'assessmentDelegate' not found on object of type 'UINavigationBar *' However it should be type of class MyCustomNavigationBar 显然有委托(delegate):

@protocol MyCustomNavigationBarDelegate;

@interface MyCustomNavigationBar : UINavigationBar

@property (weak, nonatomic) id <MyCustomNavigationBarDelegate> assessmentDelegate;

@end

@protocol MyCustomNavigationBarDelegate <NSObject>

-(void)presentViewController:(UIAlertController *)alert;

@end

最佳答案

将您的导航栏转换到底部导航栏

MyCustomNavigationBar  *switchNav = (MyCustomNavigationBar *)nav.navigationBar;
switchNav.assessmentDelegate = self

关于ios - 为自定义 UINavigationBar 设置委托(delegate),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37274218/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com