I want to create a subclass of UINavigationController that always starts with the same root controller. Nothing special, so (for me) it makes sense to redefine the init method like this:
- (id) init {
rootController = [[MyController alloc] init];
if (self = [super initWithRootViewController:rootController]) {
}
return self;
}
This obviously creates a problem because [super initWithRootViewController] will call [UINavigationController init], which of course is our overridden init method, so infinite recursion will occur.
I do not want to create an init method with a different name, for example, initCustom.
Currently, there is only one solution that I can come up with, but I really hate this kind of hack:
- (id) init {
if (initCalled)
return self;
initCalled = YES;
rootController = [[MyController alloc] init];
if (self = [super initWithRootViewController:rootController]) {
}
return self;
}
, : ? , - , .
EDIT: , , :
, . . , . ( , , ?)