2014-06-20 28 views
0

我開始新的學習Xcode和我使用的Xcode 5.1UINavigationController和UITabBarController的關係和UIViewController是一樣的嗎?

我準備滑出式導航欄形式這一來源:

https://github.com/John-Lluch/SWRevealViewController

在此代碼則需要通過我的UIViewController爲像這樣的參數:

FrontViewController *frontViewController = [[FrontViewController alloc] init]; 
UINavigationController *frontNavigationController = [[UINavigationController alloc] initWithRootViewController:frontViewController]; 

我這樣做時,我得到這樣的結果:

iphone 5s simulator

這是AppDelegate.m代碼以及:

#import "AppDelegate.h" 
#import "SWRevealViewController.h" 
#import "RearViewController.h" 
#import "CustomAnimationController.h" 
    #import "FrontViewController.h" 
    @interface AppDelegate()<SWRevealViewControllerDelegate> 
@end 
@implementation AppDelegate 
@synthesize window = _window; 
@synthesize viewController = _viewController; 

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 
{ 
    UIWindow *window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; 
    self.window = window; 

    RearViewController *rearViewController = [[RearViewController alloc] init]; 

     FrontViewController *frontViewController = [[FrontViewController alloc] init]; 
UINavigationController *frontNavigationController = [[UINavigationController alloc]  initWithRootViewController:frontViewController]; 

    UINavigationController *rearNavigationController = [[UINavigationController alloc] initWithRootViewController:rearViewController]; 

    SWRevealViewController *revealController = [[SWRevealViewController alloc] initWithRearViewController:rearNavigationController frontViewController:frontNavigationController]; 

    revealController.delegate = self; 

    //revealController.bounceBackOnOverdraw=NO; 
    //revealController.stableDragOnOverdraw=YES; 

    //self.viewController = revealCont; 
    self.viewController = revealController; 

    self.window.rootViewController = self.viewController; 
    [self.window makeKeyAndVisible]; 
    return YES; 
} 

,這是FrontViewController.h:

#import <UIKit/UIKit.h> 

@interface FrontViewController : UITabBarController 

@end 

問題是否塔導航欄不能處理TabBarController?

編輯: 這是我FrontViewController UI。 enter image description here

+0

我看到你的FrontViewController只是[[FrontViewController alloc] init],你有沒有添加一個childrenViewControllers到這個VC?,如果沒有,那是因爲它是空的。 – Dimentar

+0

是的,我添加了選項卡和一些東西 – MBH

回答

0

我覺得你的問題是 - (ID)initWithNibName:(的NSString *)nibNameOrNil包(一個NSBundle *)nibBundleOrNil,正試圖從XIB初始化VC,我的嘗試失敗了。

然後我嘗試這個成功:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { 
UIWindow *window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; 
self.window = window; 

UIViewController *firstVC = [UIViewController new]; 
firstVC.title = @"Title 1"; 

UIViewController *secondVC = [UIViewController new]; 
secondVC.title = @"Title 2"; 

UITabBarController *frontViewController = [[UITabBarController alloc] init]; 
[frontViewController setViewControllers:@[firstVC, secondVC]]; 

UINavigationController *frontNavigationController = [[UINavigationController alloc] initWithRootViewController:frontViewController]; 

self.window.rootViewController = frontNavigationController; 
[self.window makeKeyAndVisible]; 

return YES; 
} 

您可以將您的VC裏面故事板,給他一個標識符,並調用:

UITabBarController *tagTBC = [self.storyboard instantiateViewControllerWithIdentifier:@"tagViewController"]; 
+0

doesnt解決它:( – MBH

1

您嵌入了您的FrontViewController這是一個UITabBarControllerUINavigationController,Apple不允許。蘋果總是對此說「不」。所以你可以看看this教程。然後,嘗試將其嵌入到SWRevealViewController中。

該教程只是基本上顯示如何impliment UITabControllerUINavigationController,但它不顯示您的問題的實際答案。

根據Apple規則,您想實現的目標實際上是不允許的。因此,您可以將SWRevealViewController嵌入您的UITabController中,或者您可以刪除UITabController並使用UIViewUIButton s創建自定義TabBar,並更改UIButton的 - (IBAction)選項卡視圖。

+0

你也可以簡單地使用'UITabBar'沒有'UITabBarController',它可以做到這一點。 –

相關問題