Question

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?

Was it helpful?

Solution

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.

OTHER TIPS

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top