You can instantiate a UIViewController
class programmatically with initWithNibName:bundle:
and specify the same nib for multiple controllers. For example, I'm building a game right now that has a GameController
class that defines the basic game logic in it. The GameController
has an associated GameController.xib
file that gets loaded up in a custom initializer:
- (id)initWithOptions:(NSDictionary *)gameOptions
{
if (self = [super initWithNibName:@"GameController" bundle:nil])
{
// code here
}
return self;
}
I have a few different game types: peer-to-peer, local, & online. The game logic is the same, but the communication implementation is slightly different, so each of these is a subclass of GameController
. Based on how the application is used, it'll instantiate a different controller:
local = [[LocalGameController alloc] initWithOptions:options];
online = [[OnlineGameController alloc] initWithOptions:options];
You can see though that since these both extend GameController
, that both of these will be init'ed with GameController.xib
as its view. In this case, GameController
would be your single file owner.