IOS Project Development Layout 4
Add the UITabViewController control and the top scroll bar based on the previous frame. First, check the file layout as shown in Figure
1. Add the following to DemMainViewController:
- (void)addMainController{ _tabController=[[UITabBarController alloc] init]; [_tabController.view setFrame: [self.view bounds]]; NSArray *classStringArray = [NSArray arrayWithObjects:@"DemFirstViewController",@"DemSecondViewController",@"DemThreeViewController",@"DemFourViewController",nil]; NSMutableArray *array = [[NSMutableArray alloc] init]; for (int i = 0; i < [classStringArray count]; i++) { Class c = NSClassFromString([classStringArray objectAtIndex:i]); DemFSTFViewController *fstfViewController = [[c alloc] init]; UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:fstfViewController]; [fstfViewController release]; [array addObject:nav]; [nav release]; } [_tabController setViewControllers:array]; [self.view addSubview:_tabController.view];}
Note: The DemFirstViewController, DemSecondViewController, DemThreeViewController, and DemFourViewController classes inherit from the DemFSTFViewController base class and serve as the four controllers of TabBarViewController.
2. You can define a public method in DemFSTFViewController as follows:
- (void)setTitle:(NSString *)title withImageName:(NSString *)imageName{ self.title = title; self.tabBarItem.image = [UIImage imageNamed:imageName]; self.navigationItem.title = title;}
Note: This method can be used to set title and tabbarItem for each subclass that inherits it.
The running result is as follows:
Figure 1
Download link: http://download.csdn.net/detail/chchong1234/6993253