我的iPhone应用程序左上角有一个信息按钮,我不得不使用代码添加它,因为条形按钮项不支持信息按钮,代码如下...
UIButton *btn = [UIButton buttonWithType:UIButtonTypeInfoLight]; self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:btn];
我希望这个按钮推送到一个名为AboutViewController的UIViewController,我需要做些什么来使这个代码能够完成这项工作,已经尝试了很长时间.
谢谢.
您必须为要指定的控件事件执行的按钮添加选择器.
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]; }