0

From the rootViewController I navigate to a UIViewController

if (self.contr == nil) {
    ExampleViewController *controller = [[ExampleViewController alloc] 
                                   initWithNibName:@"Example" 
                                   bundle:[NSBundle mainBundle]];
    self.contr = controller;
    [controller release];
}
[self.navigationController presentModalViewController:self.contr animated:YES];

In the UIViewController I have the method

-(IBAction) goBack:(id)sender {
    [self.navigationController dismissModalViewControllerAnimated:YES];
}

I added the signature to the .h file. In the .xib file, I have a UIToolbar with a UIBarButtonItem. I connected the button to the File's Owner - goBack:

Everything appears in the screen, but when I click on the button, goBack isn't called. I also tried to do this programatically instead, but I got the same result - everything appears, but no reaction to the click.

Any ideas why it isn't working?

Edit: I just found out something invisible is over the toolbar. If I click on a specific point (over the toolbar), then goBack: is called. Since I navigated to this screen using presentModelViewController, the navigation bar isn't appearing... but probably it's there and that's what is hiding the tool bar.

Adriana
  • 806
  • 11
  • 36
  • @Adriana Post Button declaration code – Rams Jun 09 '11 at 12:53
  • Add a line to Check if sender == UIBarButtonItem – Legolas Jun 09 '11 at 14:09
  • Have you tried inserting a call to `NSLog` in the `goBack` method, or to set inside it a breakpoint to see if it is not called or if it has no effect? – marzapower Jun 09 '11 at 14:16
  • I put a breakpoint at goBack: and I don't reach it... – Adriana Jun 09 '11 at 14:16
  • Which event did you bind the action to? – marzapower Jun 09 '11 at 14:28
  • In a UIBarButtonItem, I can't bind it to an event like in UIButton. I can just set the target and action. However, it should call the method it is binded to, when clicking. – Adriana Jun 09 '11 at 14:37
  • Did you try NSLogging in -(IBAction) goBack:(id)sender ? Does the control go there ? – Legolas Jun 09 '11 at 16:45
  • I found the problem, but I didn't find a solution: since I'm calling the presentModelViewController, the UINavigationItem in the top doesn't appear. However, it is there and it's over the toolbar I created. Please read "Edit" in my question for more details. – Adriana Jun 09 '11 at 16:50

4 Answers4

0

If you are not hitting the breakpoint that means you did not connect them properly in the xib.

Chris
  • 1,539
  • 13
  • 25
0

Have bind your Toolbar with File Owner?
As your UIBarButton is subview of UIToolbar so you have to bind Toolbar with File Owner.

dks1725
  • 1,631
  • 1
  • 20
  • 29
  • The toolbar is inside the view, and the view is binded to the file's owner. Anyway, I created an IBOutlet UIToolbar and bind it to see if it would solve the problem, but it didn't. – Adriana Jun 09 '11 at 13:40
  • It's a subclass of UIViewController. – Adriana Jun 09 '11 at 14:24
0

Presenting a modal view controller do not require you to pass through a UINavigationController. I suggest you to change this:

[self.navigationController presentModalViewController:self.contr animated:YES];
[self.navigationController dismissModalViewControllerAnimated:YES];

to this:

[self presentModalViewController:self.contr animated:YES];
[self dismissModalViewControllerAnimated:YES];

Let me know if this helps.

marzapower
  • 5,531
  • 7
  • 38
  • 76
0

Try this in the goBack method :

  [self.navigationController popToRootViewControllerAnimated:YES];
Legolas
  • 12,145
  • 12
  • 79
  • 132