【问题标题】:Info button push to UIViewController信息按钮推送到 UIViewController
【发布时间】:2014-02-04 17:03:34
【问题描述】:

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

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

我希望这个按钮推送到一个名为 AboutViewController 的 UIViewController,我需要对这段代码做些什么来使它工作,已经尝试了很长时间。

谢谢。

【问题讨论】:

    标签: ios uiviewcontroller uibutton


    【解决方案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];
    }
    

    【讨论】:

    • 嗨,不知道在哪里放置“AboutViewController”以使其工作
    • @CarlRydings 你在哪里配置AboutViewController?代码/故事板/xib?
    • main.storyboard(自定义类:AboutViewController)和 AboutViewController.h 和 .m 作为 Objective-C 类
    • @CarlRydings 查看我编辑的代码,您必须在 Interface Builder 中为视图控制器分配故事板 ID,但这应该足以让您了解该做什么。
    • 谢谢,我已经做到了。但是,XCode 在代码的第二部分给了我这个错误:Use of undeclared identifier 'controller' 和 Use of undeclared identifier 'AboutViewController'
    猜你喜欢
    • 2016-01-30
    • 1970-01-01
    • 2011-11-07
    • 2011-05-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多