UINavigationBarItem以编程方式

编程入门 行业动态 更新时间:2024-10-11 21:21:44
本文介绍了UINavigationBarItem以编程方式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有从 UINavigationController 继承的视图控制器。 在 viewDidLoad 上,我要设置 rightBarButtonItem 。 我会关注。

I have view controller which is inherited from UINavigationController. On viewDidLoad I want to set rightBarButtonItem. I do following.

UINavigationItem* navItem = self.navigationItem; UIButton* btnOptionsView = [[UIButton alloc] init]; [btnOptionsView setImage:[UIImage imageNamed:@"options.png"] forState:UIControlStateNormal]; [btnOptionsView sizeToFit]; UIBarButtonItem* btnOptions = [[UIBarButtonItem alloc] initWithCustomView:btnOptionsView]; navItem.rightBarButtonItem = btnOptions;

但该按钮不可见,在调试模式下,我注意到 btnOptions。 width 为0,而且我无法为 navItem 设置标题,诸如此类

but the button is invisible, in debug mode I have noticed that btnOptions.width is 0, and also I can't set the title for navItem, something like this

[navItem setTitle:@"title"]

不会更改 UINavigationItem 的标题。

推荐答案

子类化UINavigationController。从苹果文档中获取:

You should not subclassing UINavigationController. From apple documentation:

UINavigationController类实现了专用视图控制器,该控制器管理分层内容的导航。该类不适用于子类化。而是在希望应用程序的用户接口反映内容的层次结构的情况下,按原样使用实例。

The UINavigationController class implements a specialized view controller that manages the navigation of hierarchical content. This class is not intended for subclassing. Instead, you use instances of it as-is in situations where you want your application’s user interface to reflect the hierarchical nature of your content.

更多推荐

UINavigationBarItem以编程方式

本文发布于:2023-11-02 09:54:29,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1552066.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:方式   UINavigationBarItem

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!