Reputation: 3709
I have created button for home like this:
UIBarButtonItem * addButton=[[UIBarButtonItem alloc] initWithTitle:@"Home" style:UIBarButtonItemStyleBordered target:self action:@selector(GoToHome:)];
[navItem setLeftBarButtonItem:addButton];
GoToHome function has only one line i.e:
[self.navigationController popToRootViewControllerAnimated:YES];
but when i click the Home button it shows no action (not working)
Upvotes: 1
Views: 1099
Reputation: 2218
Use this method:
UIBarButtonItem *flipButtons = [[UIBarButtonItem alloc] initWithTitle:@"Back"
style:UIBarButtonItemStyleBordered target:self
action:@selector(GotoTopScreen)];
self.navigationItem.leftBarButtonItem = flipButtons;
[flipButtons release];
-(void)GotoTopScreen
{
[self.navigationController popToRootViewControllerAnimated:YES];
}
Upvotes: 0
Reputation: 4170
try this inside your GoToHome method
[self.parentViewController.parentViewController.parentViewController dismissModalViewControllerAnimated:YES];
Upvotes: 2
Reputation: 920
The best way to create a navigation controller is to create it in appDelegate and access it as appDelegate.navigationController. Then those nil object issues do not come.
Upvotes: 0
Reputation: 784
Try this,
UIBarButtonItem *addButton = [[UIBarButtonItem alloc] initWithTitle:@"Home" style:UIBarButtonItemStylePlain target:self action:@selector(GotoTopScreen)];
self.navigationItem.rightBarButtonItem = addButton;
-(void)GotoTopScreen{
[self.navigationController popToRootViewControllerAnimated:YES];
}
Upvotes: 0
Reputation: 1569
have you connected the button code with the IB button? that can happen a lot and with everyone..!!
Upvotes: 1