In my app I have a UIViewController
and a UIView
named
- HomeViewController
- HomeView
They are both being loaded from a nib and the nib files are 开发者_运维知识库named the same as the class names When I try to initialize my ViewController:
HomeViewController *h = [[HomeViewController alloc] init];
It tries to load the viewController using the nib file for my UIView instead of the nib for my ViewController, If i load using initWithNibNamed
it works fine.
Is this a bug in iOS I have never had this problem before. I am running against iOS 5 beta 5
It is the way that you are naming your view and viewcontroller which is causing the problem. From Apple's documentation (look at the nibName property)
If the view controller class name ends with the word “Controller”, as in MyViewController, it looks for a nib file whose name matches the class name without the word “Controller”, as in MyView.nib.
It looks for a nib file whose name matches the name of the view controller class. For example, if the class name is MyViewController, it looks for a MyViewController.nib file.
If you changed the HomeView to MyHomeView for example, your code will start working again. BUT using initWithNibName: method is the recommended way for initializing a ViewController
精彩评论