2

I am facing the problem that when I push my viewcontroller in the navigationcontroller all it does is changing the navigationbar and showing the standard background but no view is to be seen. My code for pushing the viewcontroller into the navigationcontroller looks like:

Viewcontroller1 *viewController = [[Viewcontroller1 alloc] autorelease];
[[self navigationController] pushViewController:viewController animated:YES];

But, if I initialise the viewcontroller by creating IBOutlets for it, it works just fine. But the reason why I am not doing that is because I later on needs to pass some parameters to the class on initialization.

Thanks for your time.

4
  • You are totally abusing the system doing this - no wonder you have huge problems. You should create the object normally. The view controller does not call viewDidLoad until someone accesses its view property, so you have lots of opportunity to configure properties BEFORE you then go and push it. Commented Jul 31, 2012 at 11:16
  • Okay, I am new to ios programming this so wasn't aware of that. Thanks. But what do you exactly mean by creating the object normally ? Commented Jul 31, 2012 at 11:30
  • [[MyViewController alloc] initWithNib:@"MyViewController" bundle:nil]; Commented Jul 31, 2012 at 11:35
  • obvious error is absence of init (or init-like initialized) after alloc. Commented Nov 6, 2013 at 16:18

1 Answer 1

3

You have to initialise your view like

if you have xib then

Viewcontroller1 *viewController = [[[Viewcontroller1 alloc] initWithNibName:@"Viewcontroller1" bundle:nil]autorelease];
[[self navigationController] pushViewController:viewController animated:YES];

if you haven't xib

Viewcontroller1 *viewController = [[[Viewcontroller1 alloc] init]autorelease];
[[self navigationController] pushViewController:viewController animated:YES];
Sign up to request clarification or add additional context in comments.

14 Comments

I already tried that and wont work neither. All the Viewcontrollers are within the same xib. It gives the exception: *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[Viewcontroller1 initWithNibName:]:
Using your seconds method, with just "init" results in a blank page without the view but just the navigationbar.
check with this line viewController.title=@"View"; add this line before navigation and after initialization. if you get the title view in your navigation that means it navigate to ViewController1
It does give the proper title. So yes it navigates, but doesn't show any view.
can you post your ViewController's viewDidload method?
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.