Using initWithNibName changes absolutely nothing

2019-08-22 16:18发布

问题:

I'm trying to load a view controller with a different XIB, but for some unknown reasons it seems that it does not load it at all.

Usually my code is something like this:

WorkflowViewController *workflowViewController = [[WorkflowViewController alloc] init];

[self.navigationController pushViewController:workflowViewController
                                     animated:YES];
[workflowViewController release];

And now I want to load another xib with the same controller so I tried:

WorkflowViewController *workflowViewController = [[WorkflowViewController alloc] initWithNibName:@"Workflow"
                                                                                          bundle:[NSBundle mainBundle]];
[self.navigationController pushViewController:workflowViewController
                                     animated:YES];
[workflowViewController release];

But it does absolutely nothing! No errors, no warnings, and no xib loaded. Only a blank interface is pushed to the navigation controller :/

Any ideas about why it does so and how to fix it?

Thanks!

  • Tom

回答1:

did you try to use nil instead of [NSBundle mainBundle] ?

WorkflowViewController *workflowViewController = [[WorkflowViewController alloc] initWithNibName:@"Workflow" bundle:nil];
[self.navigationController pushViewController:workflowViewController
                                 animated:YES];
[workflowViewController release];


回答2:

I fixed the problem by creating another controller and another view. Then linked all the stuff back together. It seemed like the views was binded to the controller and nothing was able to change it...



回答3:

I had the same problem and turns out my equivalent of your "WorkFlowViewController" had an empty implementation of "loadView" which wasn't calling super so that