我实施了以下内容:
UIImage *rightimage = [UIImage imageNamed:@"notification-new.png"];
UIBarButtonItem *rightbutton = [[UIBarButtonItem alloc] initWithImage:rightimage style:UIBarButtonItemStylePlain target:nil action:@selector(goNotificationNow)];
self.navigationItem.rightBarButtonItem = rightbutton ;
self.navigationItem.rightBarButtonItem.tintColor = [UIColor whiteColor];
基本上,我希望按钮在按下时按下另一个ViewController,所以我设置" goNotificationNow" as:
- (void)goNotificationNow
{NotificationsViewController *ok = [[NotificationsViewController alloc]init];
[self.navigationController pushViewController:ok animated:YES];
}
现在可以按下按钮但不执行任何操作。我必须从根本上遗漏一些东西似乎无法找出它是什么。我也试过使用故事板。并将功能更改为:
- (void)goNotificationNow
{[self performSegueWithIdentifier:@"notifications" sender:self];}
答案 0 :(得分:3)
您的目标是nil
。您应该将其设置为self
。目标是将执行选择器调用的对象。
答案 1 :(得分:2)
您需要设置操作的目标,在这种情况下,您可能希望将target:nil
更改为target:self
。