我刚刚创建了标签栏控制器,侧面菜单我输出了黑屏,但我不知道如何在app委托中分配两个视图控制器请告诉我如何使其工作。我需要特定的代码才能使其工作。
//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 :(得分:0)
我没有权限对您的代码发表评论。 所以我在你的答案中发帖。
为什么在代码中设置窗口的根视图控制器两次,它总是一个。
要么,
self.window.rootViewController =self.tabBarController;
或者这个,
self.window.rootViewController=self.viewController;
答案 1 :(得分:0)
https://github.com/gotosleep/JASidePanels
如果您不想担心自己这样做,请参阅App委托文件的GIST:
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
这是有效的,这里有证据:
一切正常,您可以非常轻松地自定义侧面,这并不像其他侧面控制器那样打破。如果你有问题,请提出问题!
另外,请确保将自己的自定义图像添加到选项卡。这没有任何障碍,你现在将拥有一个非常强大的导航系统,可以使用prostyle。事实上,这个JASidePanels可能是最受欢迎的制作应用程序之一,因为它不会偷工减料并且不会打破那些让他非常擅长的人。此外,这花了我大约10分钟的时间,这只是一个开始,你可以用这个小侧板库比其他人做更多。这个库实际上需要4个文件,没有它,没有混乱,没有大惊小怪,没有愚蠢。