Ok in your next line you try to present newViewController as a modal. That will only work if newViewController actually contains an instance of a NewViewController, and THAT will only be true if you execute code that creates a NewViewController. You didn't, so it doesn't.

You need an alloc/init call, or if you are using storyboards, you need to load your view controller from the storyboard. Take a look at the instance methods in UIStoryBoard and see if any of them will create a new view controller for you.

Regards,
Duncan C
WareTo

Animated GIF created with Face Dancer, available for free in the app store.

I don't know why I did not see that.But I stil get this error:I put in '

2013-02-21 16:00:46.509 M.I.L[586:c07] Warning: Attempt to present '<'NewViewController: 0xa3a64f0'>' on '<'UITabBarController: 0xa572c00'>' whose view is not in the window hierarchy!

Why is that?

You almost never use init to create a view controller. Instead, you should use either initWithNibName:bundle: (to create the view controller from an XIB file) or the storyboard method instantiateViewControllerWithIdentifier if you are loading a view controller from a storyboard file, like it sounds like you are doing.

However, the error message sounds to me like the tab bar controller from which you are trying to present the new view controller is not on-screen.

You need to give more background. How is the tab bar controller being created? Where is the code you are posting being executed? What invokes it? (post the whole method, as well as describing how that method is being invoked.)

Regards,
Duncan C
WareTo

Animated GIF created with Face Dancer, available for free in the app store.

If you are using storyboards and your view controller is in your storyboard that you want to present modally, then create a modal segue from your View to the ViewController. Not from a button but from the view itself. Name the segue something. i.e. 'segueToModal'

Then in your code when you want to present your new view controller just call,

[self performSegueWithIdentifier:@"segueToModal" sender:self];

In your PrepareForSegue Method, check the segue identifier and do any setup needed

If you are using storyboards and your view controller is in your storyboard that you want to present modally, then create a modal segue from your View to the ViewController. Not from a button but from the view itself. Name the segue something. i.e. 'segueToModal'

Then in your code when you want to present your new view controller just call,

[self performSegueWithIdentifier:@"segueToModal" sender:self];

In your PrepareForSegue Method, check the segue identifier and do any setup needed

As long as the variable gets set after the modal is displayed and you dont want it displayed again. Since you didnt post code, I was just indicating that the logic you had would continually present the modal controller.