Richard Knop
Richard Knop

Reputation: 83695

Thread 1: Signal SIGBART

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:

enter image description here

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:

enter image description here

Any ideas how to solve it? I have run out of ideas. I am using the latest XCode.

Upvotes: 1

Views: 187

Answers (1)

btype
btype

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

Related Questions