首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 移动开发 > 移动开发 >

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

2013-10-18 
应用一个类轻松实现UITabBar and UINavigationController的界面跳转相信大家在iOS界面开发中经常会用到UIT

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

相信大家在iOS界面开发中经常会用到UITabBar and UINavigationController

今天就给大家写个简单的方法实现这个功能

这里我会用到一个类和一个plist文件

首先我们可以先创建5个界面出来

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

这是我创建的5个界面


然后我们再创建一个plist文件

具体方法

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

这样就可以创建一个plist文件,然后我们在里面写入以下内容

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

接下来我们再创建一个叫做ConfigCenter的类

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

然后再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

{

   staticNSDictionary *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


效果就如图:

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


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

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






热点排行