I do have a little Problem.
Since my UIViewControlles are all named in the same scheme:
MyView1Controller.h
MyView1Controller.m
MyView1.xib
MyView2Controller.h
MyView2Controller.m
MyView2.xib
MyView3Controller.h
MyView3Controller.m
MyView3.xib
I would now prefer to init my UIViewControllers via a factory method.
Therefore I would implement a Cateogry on UIViewController:
static NSString *standardNibFileName;
@interface UIViewController (FactoryInstantiation)
+ (id) standardViewController;
@end
And in MyView1Controller controller I would declare the static nib file name variable:
static NSString *standardNibFileName = @"MyView1";
@implementation MyView1Controller
Then I could instantiate all my UIViewCOntrollers using the method:
@implementation UIViewController (FactoryInstantiation)
+ (id) standardViewController;
{
if(standardNibFileName != nil) {
NSString *className = NSStringFromClass([self class]);
Class classToIntantiate = NSClassFromString(className);
return [[classToIntantiate alloc] initWithNibName:className bundle:nil];
}
return nil;
}
@end
Init:
MyView1Controller *a = [MyView1Controller standardViewController];
But the static variable is always nil.
Any suggestions on how to solve this issue?
I would appreciate any help!
Thanks in advance.
You can declare a + method instead on
UIViewControllerclass and override on the implementing classesEdit: If the implementing class has the same nibName as the base you don’t have to override the function.