1

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?

User97693321
  • 3,336
  • 7
  • 45
  • 69
user1120133
  • 3,244
  • 3
  • 48
  • 90
  • Where are you putting that code that initializes the done button? Have you tried adding an NSLog statement inside the "dismissView:" selector to determine if it is actually being invoked? – nickbona Jan 16 '12 at 21:59
  • How i can initialize the done button? – user1120133 Jan 16 '12 at 22:08

2 Answers2

1
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

otakuProgrammer
  • 298
  • 2
  • 12
1

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.

Hiren
  • 12,720
  • 7
  • 52
  • 72