Najeebullah Shah
Najeebullah Shah

Reputation: 3709

Go Back to home screen

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

Answers (5)

Ravi Kumar Karunanithi
Ravi Kumar Karunanithi

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

iPhone
iPhone

Reputation: 4170

try this inside your GoToHome method

 [self.parentViewController.parentViewController.parentViewController dismissModalViewControllerAnimated:YES];

Upvotes: 2

utsabiem
utsabiem

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

Rajesh
Rajesh

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

newton_guima
newton_guima

Reputation: 1569

have you connected the button code with the IB button? that can happen a lot and with everyone..!!

Upvotes: 1

Related Questions