Want to highlight a helpful answer? Upvote!

Did someone help you, or did an answer or User Tip resolve your issue? Upvote by selecting the upvote arrow. Your feedback helps others! Learn more about when to upvote >

Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

Problem with UIBarButtonItem

Im having a problem trying to get my home button UIBarButtonItem back to my initial ViewController.


I have this code within the viewDidLoad method:


// Create a home button

UIBarButtonItem *homeButton = [[UIBarButtonItemalloc] initWithTitle:@"Home"style:UIBarButtonItemStylePlaintarget:selfaction:@selector(goHome:)];

[self.navigationItemsetLeftBarButtonItem:homeButton animated:NO];


// Go to home page

- (void) goHome {

ViewController *view1 = [[ViewControlleralloc]initWithNibName:@"ViewController"bundle:nil];

[selfpresentViewController:view1 animated:YEScompletion:nil];

}


When I try and invoke the function goHome by clicking the button, I get NSInvalidArgumentException


Thanks in advance 🙂

Posted on Apr 7, 2013 12:54 PM

Reply
Question marked as Best reply

Posted on Apr 7, 2013 5:04 PM

Your goHome method takes no parameters, try removing the colon(:).


action:@selector(goHome)];


instead of


action:@selector(goHome:)];

4 replies

Apr 8, 2013 4:45 AM in response to xnav

Thanks 🙂


That worked perfectly!


Is there a more efficient way of getting back to my first initial ViewController without making an instantiated copy again of my ViewController class as its already being instantiated within the appDelegate.


My initial ViewController navigates to my ViewControllerSecond via a round rect button. My ViewControllerSecond is nested within a UINavigationController and its this UINavigationController that has my Home Button within.


Many thanks!

Problem with UIBarButtonItem

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.