ios - 为自定义 UINavigationBar 设置委托(delegate)
<p><p>我正在尝试添加自定义元素,包括从我的 <code>navigationBar</code> 更改的下拉菜单和 View ,因此我需要一个自定义元素。但是,当尝试将委托(delegate)设置为我的 ViewController 时,它会引发错误。</p>
<pre><code>@interface MyViewController : UIViewController <MyCustomNavigationBarDelegate>
@implementation MyViewController
- (void)viewDidLoad {
;
UINavigationController *nav = [ initWithNavigationBarClass: toolbarClass:];
nav.navigationBar.assessmentDelegate = self;
}
</code></pre>
<p>最后一行抛出错误 Property '<code>assesmentDelegate</code>' not found on object of type '<code>UINavigationBar</code> *' 但是它应该是类的类型 <code>MyCustomNavigationBar</code> 显然有委托(delegate):</p>
<pre><code>@protocol MyCustomNavigationBarDelegate;
@interface MyCustomNavigationBar : UINavigationBar
@property (weak, nonatomic) id <MyCustomNavigationBarDelegate> assessmentDelegate;
@end
@protocol MyCustomNavigationBarDelegate <NSObject>
-(void)presentViewController:(UIAlertController *)alert;
@end
</code></pre></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>将您的导航栏转换到 <code>MyCustoms 导航栏</code></p> <pre><code>MyCustomNavigationBar*switchNav = (MyCustomNavigationBar *)nav.navigationBar;
switchNav.assessmentDelegate = self
</code></pre></p>
<p style="font-size: 20px;">关于ios - 为自定义 UINavigationBar 设置委托(delegate),我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/37274218/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/37274218/
</a>
</p>
页:
[1]