IOS開發之UITabBarController與UINavigationController混合使用


ios開發中UITabBarController與UINavigationController混合使用是很多app的基礎頁面結構,下面是簡單的的頁面初始化的方法,在AppDelegate.m的

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions

  中加入如下代碼

   self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    self.window.backgroundColor = [UIColor whiteColor];
    [self.window makeKeyAndVisible];
    //初始化tabbar並設置為根視圖
    tabBarViewController = [[UITabBarController alloc]init];
    [self.window setRootViewController:tabBarViewController];
    
    //初始化視圖並注入tabbar作為子視圖
    MainViewController* first = [[MainViewController alloc]init];
    first.title = @"首頁";
    first.tabBarItem = [[UITabBarItem alloc]initWithTitle:@"首頁" image:[UIImage imageNamed:@"singleicon.png"]  selectedImage:[UIImage imageNamed:@"singleicon.png"] ];
    //初始化navigation並把navigation加入到tabbar中
    UINavigationController * navFirst = [[UINavigationController alloc]initWithRootViewController:first];
    [tabBarViewController addChildViewController:navFirst];
    
    
    BobMyInfoTableViewController* second = [[BobMyInfoTableViewController alloc]init];
    second.title = @"我的信息";
    second.tabBarItem = [[UITabBarItem alloc]initWithTitle:@"" image:[UIImage imageNamed:@"doubleicon.png"] selectedImage:[UIImage imageNamed:@"doubleicon.png"]];
     UINavigationController * navSec = [[UINavigationController alloc]initWithRootViewController:second];
    [tabBarViewController addChildViewController:navSec];

有錯誤歡迎指正。Stay Hungry Stay Foolish


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM