pushViewController and popToRootViewController

1.2k views Asked by At

My application is using pushViewController to show the navigation controller modally

 [navigationController pushViewController:_viewController animated:YES];

Navigation Controller has done button

UIButton* backButton = [UIButton buttonWithType:101]; 
[backButton addTarget:self action:@selector(dismissView:) forControlEvents:UIControlEventTouchUpInside];
[backButton setTitle:@"Done" forState:UIControlStateNormal];

UIBarButtonItem* backItem = [[UIBarButtonItem alloc] initWithCustomView:backButton];

self.navigationItem.leftBarButtonItem = backItem;
[backItem release];

When done button is pressed I want that it should navigate back to main window

-(void) dismissView: (id)sender

{
    [self.navigationController popToRootViewControllerAnimated:YES];
//[self.navigationController popToViewController:_viewController animated:YES];

}

But when I press on done button nothing happens. Why is that?

2

There are 2 answers

0
Hiren On BEST ANSWER

Please NSLog in your dissmissView

-(void) dismissView: (id)sender

{
   NSLog(@"Hii....");
    [self.navigationController popToRootViewControllerAnimated:YES];
//[self.navigationController popToViewController:_viewController animated:YES];

}

or debug the app with break point.

0
otakuProgrammer On
UIButton* backButton = [UIButton buttonWithType:101];

im quite sure "101" is invalid

+ (id)buttonWithType:(UIButtonType)buttonType

you should use one of the following UIButtonType values

typedef enum {
    UIButtonTypeCustom = 0,
    UIButtonTypeRoundedRect,
    UIButtonTypeDetailDisclosure,
    UIButtonTypeInfoLight,
    UIButtonTypeInfoDark,
    UIButtonTypeContactAdd,
} UIButtonType;

other than that test your code put some NSLog in your dismissView: to see if it gets called