应用一个类轻松实现UITabBar and UINavigationController的界面跳转

相信大家在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


最后我们在AppDelegate.m中

#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


效果就如图:



希望这个方法可以帮到大家!

接下来还会继续实现各个界面的真正功能,希望大家能够支持!






  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值