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
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!

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

Problem with UIBarButtonItem

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