以编程方式向 UINavigationBar 添加后退按钮?

编程入门 行业动态 更新时间:2024-10-26 12:28:02
本文介绍了以编程方式向 UINavigationBar 添加后退按钮?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在使用以下代码在我的应用中实现导航栏.(当我使用推送转场时,我的应用程序崩溃了,所以我需要一个模态转场,这意味着在调用模态转场后导航栏是隐藏的)

I am using the following code to achieve a navigation bar in my app. (my app was crashing when I used a push segue so I need a modal segue meaning the nav bar is hidden after the modal segue is called)

UINavigationBar *navbar = [[UINavigationBar alloc]initWithFrame:CGRectMake(0, 0, 320, 50)]; //do something like background color, title, etc you self [self.view addSubview:navbar];

有谁知道我可以通过上面的代码使用什么方法来实现导航栏中的后退按钮功能??

Does any one know any methods I can use with the above code to achieve back button functionality in the nav bar??

推荐答案

使用下面的代码在左侧添加返回按钮

UINavigationBar *navbar = [[UINavigationBar alloc]initWithFrame:CGRectMake(0, 0, 320, 50)]; //do something like background color, title, etc you self [self.view addSubview:navbar]; UINavigationItem *item = [[UINavigationItem alloc] init]; navbar.items= @[item]; UIBarButtonItem *backButton = [[UIBarButtonItem alloc] initWithTitle:@"Back" style:UIBarButtonItemStyleBordered target:self action:@selector(backBtnClicked:)]; item.leftBarButtonItem = backButton;

更多推荐

以编程方式向 UINavigationBar 添加后退按钮?

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

发布评论

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

>www.elefans.com

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