但是,我正在创建这样的 ViewController:(然后我不能制作#define,或者输入不同的名称)
(UINavigationController *)createNavigationControllerWrappingViewControllerForDataSourceOfClass:(Class)datasourceClass {
id<VideosDataSource,UITableViewDataSource> dataSource = [[datasourceClass alloc] init];
// create the VideosTableViewController and set the datasource
VideosTableViewController *theViewController;
theViewController = [[VideosTableViewController alloc] initWithDataSource:dataSource];
// create the navigation controller with the view controller
UINavigationController *theNavigationController;
theNavigationController = [[UINavigationController alloc] initWithRootViewController:theViewController];
// before we return we can release the dataSource (it is now managed by the ElementsTableViewController instance
[dataSource release];
// and we can release the viewController because it is managed by the navigation controller
[theViewController release];
return theNavigationController;
}
(void)setupPortraitUserInterface {
// a local navigation variable
// this is reused several times
UINavigationController *localNavigationController;
// Create a tabbar controller and an array to contain the view controllers
tabBarController = [[UITabBarController alloc] init];
// define a custom frame size for the entire tab bar controller that will be in the
// bottom half of the screen.
CGRect tabBarFrame;
tabBarFrame = CGRectMake(0, 0, 320, 460);
tabBarController.view.frame = tabBarFrame;
NSMutableArray *localViewControllersArray = [[NSMutableArray alloc] initWithCapacity:6];
// setup the 6 view controllers for the different data representations
// create the view controller and datasource for the VideosSortedBySuggestionsDataSource
// wrap it in a UINavigationController, and add that navigationController to the
// viewControllersArray array
localNavigationController = [self createNavigationControllerWrappingViewControllerForDataSourceOfClass:[VideosSortedBySuggestionsDataSource class]];
[localViewControllersArray addObject:localNavigationController];
// the localNavigationController data is now retained by the application delegate
// so we can release the local variable
[localNavigationController release];
// repeat the process for the VideosSortedBySuggSearchDataSource
localNavigationController = [self createNavigationControllerWrappingViewControllerForDataSourceOfClass:[VideosSortedBySuggSearchDataSource class]];
[localViewControllersArray addObject:localNavigationController];
// the localNavigationController data is now retained by the application delegate
// so we can release the local variable
[localNavigationController release];
// repeat the process for the VideosSortedByMostViewedDataSource
localNavigationController = [self createNavigationControllerWrappingViewControllerForDataSourceOfClass:[VideosSortedByMostViewedDataSource class]];
[localViewControllersArray addObject:localNavigationController];
// the localNavigationController data is now retained by the application delegate
// so we can release the local variable
[localNavigationController release];
// repeat the process for the VideosSortedByTopRatedDataSource
localNavigationController = [self createNavigationControllerWrappingViewControllerForDataSourceOfClass:[VideosSortedByTopRatedDataSource class]];
[localViewControllersArray addObject:localNavigationController];
// the localNavigationController data is now retained by the application delegate
// so we can release the local variable
[localNavigationController release];
// repeat the process for the VideosSortedBySearchDataSource
localNavigationController = [self createNavigationControllerWrappingViewControllerForDataSourceOfClass:[VideosSortedBySearchDataSource class]];
[localViewControllersArray addObject:localNavigationController];
// the localNavigationController data is now retained by the application delegate
// so we can release the local variable
[localNavigationController release];
// repeat the process for the VideosSortedBySearchDataSource
localNavigationController = [self createNavigationControllerWrappingViewControllerForDataSourceOfClass:[VideosSortedBySearchDataSource class]];
[localViewControllersArray addObject:localNavigationController];
// the localNavigationController data is now retained by the application delegate
// so we can release the local variable
[localNavigationController release];
// set the tab bar controller view controller array to the localViewControllersArray
tabBarController.viewControllers = localViewControllersArray;
// the localViewControllersArray data is now retained by the tabBarController
// so we can release this version
[localViewControllersArray release];
// set the window subview as the tab bar controller
[self.view addSubview:tabBarController.view];
}