Reputation: 83695
So I have two views that I am trying to connect with a navigation.
I have embedded them in a navigation controller and created a push segue between them in the storyboard:
It the viewDidLoad of the first controller I add a button to the navigation together with a method it should call when clicked:
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
UIBarButtonItem *myButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemRefresh target:self action:@selector(buttonClicked:)];
self.navigationItem.rightBarButtonItem = myButton;
}
- (void)buttonClicked
{
NSLog(@"hello");
}
It compiles fine and I can run it in the simulator but when I click on the button in the navigation bar, instead of logging "hello", I get:
Any ideas how to solve it? I have run out of ideas. I am using the latest XCode.
Upvotes: 1
Views: 187
Reputation: 1576
Try to remove the :
in your target action:
UIBarButtonItem *myButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemRefresh target:self action:@selector(buttonClicked)];
if you want to use the colon define your method like this:
- (void)buttonClicked:(id)sender
{
NSLog(@"hello");
}
Upvotes: 6