相信大家在iOS界面开发中经常会用到UITabBar and UINavigationController
今天就给大家写个简单的方法实现这个功能
这里我会用到一个类和一个plist文件
首先我们可以先创建5个界面出来
这是我创建的5个界面
然后我们再创建一个plist文件
具体方法
这样就可以创建一个plist文件,然后我们在里面写入以下内容
接下来我们再创建一个叫做ConfigCenter的类
然后再ConfigCenter.h中定义一些属性和方法
@interface JConfigCenter :NSObject
@property (nonatomic,retain)NSMutableDictionary *config;
@property (nonatomic,copy)NSString *path;
+(id)getConfigWithKey:(NSString *)key;
+(id)getRootViewControllers;
@end
接下来我们再在ConfigCenter.m中实现
#import "JConfigCenter.h"
@implementation JConfigCenter
+(id)getRootViewControllers
{
return [selfgetConfigWithKey:kROOT_VIEW_CONTROLLERS];
}
+(id)getConfigWithKey:(NSString *)key
{
return [[selfgetConfig] objectForKey:key];
}
+(id)getConfig
{
static NSDictionary *config;
if (!config) {
NSString * path = [[NSBundlemainBundle] pathForResource:@"config"ofType:@"plist"];
config = [NSDictionarydictionaryWithContentsOfFile:path];
}
return config;
}
@end
#import "JAppDelegate.h"
#import "JConfigCenter.h"
@implementation JAppDelegate
- (void)dealloc
{
[_windowrelease];
[superdealloc];
}
-(void)buildLayout
{
UITabBarController *tbc = [[UITabBarControlleralloc] init];
NSArray *controllers = [JConfigCentergetRootViewControllers];
for (NSString *controllerin controllers) {
UIViewController *vc = [[NSClassFromString(controller)alloc] init];
UINavigationController *nav = [[UINavigationControlleralloc] initWithRootViewController:vc];
[tbc addChildViewController:nav];
}
self.window.rootViewController = tbc;
}
#pragma mark -
#pragma mark JAppDelegate lifecycle
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[[UIWindowalloc] initWithFrame:[[UIScreenmainScreen] bounds]]autorelease];
// Override point for customization after application launch.
self.window.backgroundColor = [UIColorwhiteColor];
[selfbuildLayout];
[self.windowmakeKeyAndVisible];
return YES;
}
@end
效果就如图:
希望这个方法可以帮到大家!
接下来还会继续实现各个界面的真正功能,希望大家能够支持!