信息按钮推送到UIViewController

 奶爸乳酪 发布于 2023-01-29 13:54

我的iPhone应用程序左上角有一个信息按钮,我不得不使用代码添加它,因为条形按钮项不支持信息按钮,代码如下...

UIButton *btn = [UIButton buttonWithType:UIButtonTypeInfoLight];
self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:btn];

我希望这个按钮推送到一个名为AboutViewController的UIViewController,我需要做些什么来使这个代码能够完成这项工作,已经尝试了很长时间.

谢谢.

1 个回答
  • 您必须为要指定的控件事件执行的按钮添加选择器.

    UIButton *btn = [UIButton buttonWithType:UIButtonTypeInfoLight];
    [btn addTarget:self action:@selector(iClickedMyButton:) forControlEvents:UIControlEventTouchUpInside];
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:btn];
    

    从那里开始,按照你通常的方式.

    - (void)iClickedMyButton:(UIButton *)sender
    {
        AboutViewController *controller = [self.storyboard instantiateViewControllerWithIdentifier:@"AboutVC"];
    
        [self.navigationController pushViewController:controller animated:YES];
    }
    

    2023-01-29 13:57 回答
撰写答案
今天,你开发时遇到什么问题呢?
立即提问
热门标签
PHP1.CN | 中国最专业的PHP中文社区 | PNG素材下载 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有