So I'm doing this in my code now:
UIViewController* ctrl =
[[UIViewController alloc] // i'm alloc'ing a UIViewController...
initWithNibName:@"TheNibName" // But this NIB has, within
// interface builder, a link to "UIViewControllerDERIVATIVE". So really,
// `ctrl` is a UIViewControllerDERIVATIVE instance, not just
// a UIViewController instance.
bundle:nil] ;
The reason I'm doing this is it makes a massive convenience in writing some code that pushes modal dialogs on.. since Objective-C doesn't support <template>.
M开发者_StackOverflow中文版y question is, is this ok?? Can I [alloc]
a UIViewController
only, while really what comes out of a NIB is an instance of UIViewControllerDERIVATIVE
? Or will it bite me in the ass later?
You cannot allocate an UIViewController
and initialize it as a UIViewControllerDERIVATIVE
, because there will be a mismatch between the how the two classes see their instances.
Once an instance has been allocated by a class, it is the responsibility of the class to initialize it. This is because the class of the instance is set when the instance is allocated. See NSObject reference more details.
精彩评论