Loading new Views
Ok so I'm sure I'm missing this somewhere but I think I need someone else 开发者_StackOverflow中文版to bounce this off as I've been going around in circles on this for some time.
My situation is quite straight forward really.
I've got two files TapView.m TapView.h
which are loaded when the AppController.m calls the showTapView method.
-(void) showTapView {
[tapViewController resetAllStates:self];
[navigationController pushViewController animated:YES];
[tapViewController prepareTapView];
[[UIAccelerometer sharedAccelerometer] setDelegate:tapViewController];
}
Now this all works swell and loads TapView in happily enough. It's not really an issue, but I don't like building interfaces progmatically, what I'd love to be able to do is to change this method so that instead of loading a progmatically created view it calls on a XIB based view, let's call it LazyView for the sake of arguments.
Now if it's a big thing to do this I'm happy as is and can leave it progmatically inclined, it's just that having it working through Interface Builder will help me significantly in the future as I expand the application further :)
If anyone's wondering by the way, I've built the app using some samples from open source projects, the app doesn't bear much resemblance these days but it was from Remotepad - many thanks to the guys for the release of the source, it helped me get my head around Bonjour no end.
Sounds like you are looking for the initWithNibName
method to load a view controller from a Nib.
UIViewController* controller = [[LazyViewController alloc] initWithNibName:@"LazyViewController" bundle:nil];
[self.navigationController pushViewController:controller animated:YES];
[controller release];
精彩评论