I have the following implemented:

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];

Basically, I want the button to push to another ViewController when it is pressed, so I set "goNotificationNow" as :

- (void)goNotificationNow
{NotificationsViewController *ok = [[NotificationsViewController alloc]init];
[self.navigationController pushViewController:ok animated:YES];
}

Now the button can be pressed but it does not do anything. I must be missing something fundamentally just can't seem to find out what it is. I tried using storyboard as well. and changing the function to:

- (void)goNotificationNow
{[self performSegueWithIdentifier:@"notifications" sender:self];}
有帮助吗?

解决方案

Your target is nil. You should set it to self. The target is the object that will perform the selector call.

其他提示

You need to set the target for the action, in this case you're probably wanting to change target:nil to target:self.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top