tags:

views:

148

answers:

1

So in my app delegate I add a call add the myViewController.view to the main window:
1. [window addSubview:myViewController.view];

In myViewController I do the following code in the viewDidAppear method:
2. [self presentModalViewController: yourViewController animated: YES];


In my yourViewController class I do the following to try and go back to the main window
3. [self dismissModalViewControllerAnimated:YES];

My main windows view appears with buttons in all, but the buttons won't react to any click or anything. It's like there is something over them that I can't see.

Also, the main windows button works before this process but doesn't after the process.

Any help would be appreciated.

A: 
  1. If the dismiss method call is in the modal view controller (not the parent that presents it), then you actually want to call [self.parentController dismissModalViewControllerAnimated:YES];
  2. There are a number of reasons why things might not be responding to your touches. Here are two that have happened to me:
    • The frame of the view you want to touch is too small. UIViews can draw outside of their frames, so it might look ok, but not respond if the touch is technically outside of the frame -- you also have to check that all the superview's up the hierarchy also have a large enough frame.
    • If anything in your view is a UIImageView or child thereof, it won't respond to user touches because UIImageView has userInteractionEnabled set to NO by default. You can fix this just by setting myImageView.userInteractionEnabled = YES;

Edit: Oli pointed out in the comments that dismissModalViewControllerAnimated: should work if called on either self.parentController or simply self, since that method is smart enough to call the parent if needed, according to the docs. The docs also make it sound like this might behave differently if you have multiple model views open at once, though, so I would still consider it cleaner code to call the method on self.parentController directly.

Tyler
changing it to [self.parentController dismissModalViewControllerAnimated:YES]; didn't do anything. Also, the main windows button works before this process but doesn't after the process.
TheGambler
this actually got me started. I needed to also remove the parent controllers view.
TheGambler
The UIViewController documentation (http://developer.apple.com/library/ios/#documentation/uikit/reference/UIViewController_Class/Reference/Reference.html) states that should you call dismissModalViewControllerAnimated: on the modal ViewController instead of its parent, the modal VC utomatically forwards the message to its parent view controller.
Oli