2015-08-28 83 views
0

我剛創建了帶有側面菜單的標籤欄控制器我得到了與黑色屏幕輸出,但我不知道如何分配應用程序委託兩個視圖控制器請告訴我如何使它work.i需要特定的代碼才能使其工作。在標籤欄和側面菜單中的視圖控制器問題

//AppDelegate.h 

@interface AppDelegate : UIResponder <UIApplicationDelegate,UITabBarControllerDelegate> 
{ 
    UINavigationController *navigationController; 
} 

@property (strong, nonatomic) UIWindow *window; 
@property (strong,nonatomic)UITabBarController *tabBarController; 

//AppDelegate.m

@interface AppDelegate()<SWRevealViewControllerDelegate> 
@end 

@implementation AppDelegate 
@synthesize window = _window; 
@synthesize viewController = _viewController; 


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { 
    // Override point for customization after application launch. 

    UIWindow *window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; 
    self.window = window; 

    self.tabBarController =[[UITabBarController alloc]init]; 




    //Initialize View controller and speciality 

    UIViewController *viewcontroller1=[[HomeView alloc]init]; 
    UIViewController *viewcontroller2=[[Speciality alloc]init]; 
    UIViewController *viewcontroller3=[[Activity alloc]init]; 
    UIViewController *viewcontroller4 =[[Notification alloc]init]; 
    UIViewController *viewcontroller5 =[[Profile alloc]init]; 

    self.tabBarController.viewControllers=[NSArray arrayWithObjects:viewcontroller1,viewcontroller2,viewcontroller3,viewcontroller4,viewcontroller5, nil]; 

    self.tabBarController.tabBar.barTintColor = [UIColor colorWithRed:0.376 green:0.729 blue:0.318 alpha:1.000]; 


    self.window.backgroundColor = [UIColor whiteColor]; 




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

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

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


     mainRevealController.delegate = self; 

     self.viewController = mainRevealController; 
     self.window.backgroundColor= [UIColor whiteColor]; 




     self.window.rootViewController =self.tabBarController; 


     self.window.rootViewController=self.viewController; 


    [self.window makeKeyAndVisible]; 


     return YES; 

} 
+0

我在4天前問你這個問題,我忘了回答,就像我說過的那樣,但是如果你有問題,請回頭看看你有沒有問題,現在你已經有了完整的答案 – Loxx

回答

0

阿倫,我會幫你搞到大的時候,如果你改變你的庫JASidpanels,這將是更容易爲你和我已經做出瞭解決方案。下載JASidePanels,使用這個庫,而不是,它做同樣的事情,你有一個,但它的好,在這裏下載:

https://github.com/gotosleep/JASidePanels

,如果你不想擔心這樣做你自己,這裏的應用程序的委託文件的要旨:

https://gist.github.com/anonymous/e85536b17296287ec34f

https://gist.github.com/anonymous/93b620135418ddc8f1ed

啓動示範項目,然後將所有你需要做的是改變的AppDelegate h和AppDelegate.m文件和你你想要什麼,並更多:

這裏的新AppDelegate.m:

#import "JAAppDelegate.h" 

#import "JASidePanelController.h" 
#import "JACenterViewController.h" 
#import "JALeftViewController.h" 
#import "JARightViewController.h" 

@implementation JAAppDelegate 

@synthesize window = _window; 
@synthesize viewController = _viewController; 

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

    self.viewController = [[JASidePanelController alloc] init]; 
    self.viewController.shouldDelegateAutorotateToVisiblePanel = NO; 

    self.viewController.leftPanel = [[JALeftViewController alloc] init]; 


    UIViewController *viewcontroller1=[[UIViewController alloc]init]; 
    UIViewController *viewcontroller2=[[UIViewController alloc]init]; 
    UIViewController *viewcontroller3=[[UIViewController alloc]init]; 
    UIViewController *viewcontroller4 =[[UIViewController alloc]init]; 
    UIViewController *viewcontroller5 =[[UIViewController alloc]init]; 

    viewcontroller1.view.backgroundColor = [UIColor redColor]; 

    viewcontroller2.view.backgroundColor = [UIColor blueColor]; 
    viewcontroller3.view.backgroundColor = [UIColor yellowColor]; 
    viewcontroller4.view.backgroundColor = [UIColor greenColor]; 
    viewcontroller5.view.backgroundColor = [UIColor purpleColor]; 



    UINavigationController *navcontroller1=[[UINavigationController alloc] initWithRootViewController:viewcontroller1]; 
    UINavigationController *navcontroller2=[[UINavigationController alloc] initWithRootViewController:viewcontroller2]; 
    UINavigationController *navcontroller3=[[UINavigationController alloc] initWithRootViewController:viewcontroller3]; 
    UINavigationController *navcontroller4 =[[UINavigationController alloc] initWithRootViewController:viewcontroller4]; 
    UINavigationController *navcontroller5 =[[UINavigationController alloc] initWithRootViewController:viewcontroller5]; 


    viewcontroller1.title = @"one"; 
    viewcontroller2.title = @"two"; 
    viewcontroller3.title = @"three"; 
    viewcontroller4.title = @"four"; 
    viewcontroller5.title = @"five"; 

    navcontroller1.tabBarItem.image = [UIImage imageNamed:@"cam"]; 
    navcontroller2.tabBarItem.image = [UIImage imageNamed:@"cam"]; 
    navcontroller3.tabBarItem.image = [UIImage imageNamed:@"cam"]; 
    navcontroller4.tabBarItem.image = [UIImage imageNamed:@"cam"]; 
    navcontroller5.tabBarItem.image = [UIImage imageNamed:@"cam"]; 

    self.this = [[UITabBarController alloc] init]; 

    self.this.viewControllers=[NSArray arrayWithObjects:navcontroller1,navcontroller2,navcontroller3,navcontroller4,navcontroller5, nil]; 

    //self.this.tabBar.barTintColor = [UIColor orangeColor]; 
    self.this.tabBar.backgroundColor = [UIColor orangeColor]; 


    self.viewController.centerPanel = _this; 
    self.viewController.rightPanel = [[JARightViewController alloc] init]; 

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

@end 

這裏的新AppDelegate.h:

#import <UIKit/UIKit.h> 

@class JASidePanelController; 

@interface JAAppDelegate : UIResponder <UIApplicationDelegate> 

@property (strong, nonatomic) UIWindow *window; 

@property (strong, nonatomic) JASidePanelController *viewController; 
@property (strong, nonatomic) UITabBarController *this; 


@end 

這工作,這裏的證明:

enter image description here

enter image description here

enter image description here

這一切的作品,你可以自定義邊的很容易,這不破遠遠不如其他的側面板控制器。問問你有沒有他們!

此外,請確保您將自己的自定義圖像添加到選項卡。這工作沒有困難,你現在將擁有一個非常強大的導航系統,可以工作prostyle。事實上,這個JASidePanels可能是最受歡迎的應用程序之一,因爲它不會偷工減料,也不會打破那些使他非常擅長的工作。而且,這花了我大約10分鐘的時間,這只是一個開始,你可以用這個小側面板庫做比其他更多的事情。這個庫從字面上需要4個文件,就是這樣,沒有混亂,沒有大驚小怪,沒有愚蠢。

+0

oh goddd u just made我的日子謝謝sooooo – Arun

+0

哈哈哈,沒問題,上週我告訴過你很簡單,但我忘了!你可以重複使用它並用它做各種各樣的東西,祝你好運! – Loxx

+0

給你一個大弓!非常感謝 – Arun

0

我沒有權限對你的代碼進行評論。 因此,我將其發佈在您的答案中。

爲什麼在代碼中設置了窗口的根視圖控制器兩次,它總是一個。

要麼這個,

 self.window.rootViewController =self.tabBarController; 

還是這個,

 self.window.rootViewController=self.viewController; 
相關問題