Using initWithNibName changes absolutely nothing

2019-08-22 15:25发布

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

3条回答
The star\"
2楼-- · 2019-08-22 16:05

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];
查看更多
何必那么认真
3楼-- · 2019-08-22 16:11

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...

查看更多
SAY GOODBYE
4楼-- · 2019-08-22 16:18

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

查看更多
登录 后发表回答