Frage

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];}
War es hilfreich?

Lösung

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

Andere Tipps

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

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top