Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/assembly/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 如何在Objective C中的UIViewController上添加UIAbbar控制器和UINavigation栏_Ios_Objective C_Uiviewcontroller_Uinavigationcontroller_Uitabbarcontroller - Fatal编程技术网

Ios 如何在Objective C中的UIViewController上添加UIAbbar控制器和UINavigation栏

Ios 如何在Objective C中的UIViewController上添加UIAbbar控制器和UINavigation栏,ios,objective-c,uiviewcontroller,uinavigationcontroller,uitabbarcontroller,Ios,Objective C,Uiviewcontroller,Uinavigationcontroller,Uitabbarcontroller,我是iOS新手,在UIViewController上添加uitabarcontroller和UINavigationController时遇到了一个问题。我尝试这样的代码 在AppDeleagte.m中 ViewController1 *news=[[ViewController1 alloc]initWithNibName:@"ViewController1" bundle:nil ]; ViewController2 *menu =[[ViewController2 alloc] initW

我是iOS新手,在
UIViewController
上添加
uitabarcontroller
UINavigationController
时遇到了一个问题。我尝试这样的代码

在AppDeleagte.m中

ViewController1 *news=[[ViewController1 alloc]initWithNibName:@"ViewController1" bundle:nil ];
ViewController2 *menu =[[ViewController2 alloc] initWithNibName:@"ViewController2" bundle:nil];
ViewController3 *emergency =[[ViewController3 alloc] initWithNibName:@"ViewController3" bundle:nil];
ViewController4 *calender=[[ViewController4 alloc]initWithNibName:@"ViewController4" bundle:nil];
ViewController5 *help =[[ViewController5 alloc] initWithNibName:@"ViewController5" bundle:nil];
UINavigationController *nav1=[[UINavigationController alloc]initWithRootViewController:menu];
UINavigationController *nav2=[[UINavigationController alloc]initWithRootViewController:emergency];
UINavigationController *nav3=[[UINavigationController alloc]initWithRootViewController:calender];
UINavigationController *nav4=[[UINavigationController alloc]initWithRootViewController:help];
UINavigationController *nav5 =[[UINavigationController alloc]initWithRootViewController:news];


tab=[[UITabBarController alloc]init];
tab.viewControllers=[[NSArray alloc]initWithObjects:nav1,nav2,nav5,nav3,nav4 ,nil];
UITabBarItem *tabItem = [[[tab tabBar] items] objectAtIndex:0];
[tabItem setTitle:@"Menu"];
tabItem.image=[UIImage imageNamed:@"Menu.png"];
UITabBarItem *tabItem1 = [[[tab tabBar] items] objectAtIndex:1];
[tabItem1 setTitle:@"Emergency"];
tabItem1.image=[UIImage imageNamed:@"Emergency.png"];
UITabBarItem *tabItem2 = [[[tab tabBar] items] objectAtIndex:2];
[tabItem2 setTitle:@"News"];
tabItem2.image=[UIImage imageNamed:@"News.png"];
UITabBarItem *tabItem3 = [[[tab tabBar] items] objectAtIndex:3];
[tabItem3 setTitle:@"Calender"];
tabItem3.image=[UIImage imageNamed:@"Calender.png"];
UITabBarItem *tabItem4 = [[[tab tabBar] items] objectAtIndex:4];
[tabItem4 setTitle:@"Help"];
tabItem4.image=[UIImage imageNamed:@"Help.png"];

if ([Userid isEqualToString:@"null"]) {
        Hard =[[HardSoftScreen alloc] initWithNibName:@"HardSoftScreen" bundle:nil];
        nav=[[UINavigationController alloc]initWithRootViewController:Hard];

}
else
{
    ViewController1 *news=[[ViewController1 alloc]initWithNibName:@"ViewController1" bundle:nil];
    nav=[[UINavigationController alloc]initWithRootViewController:news];
    //nav=[[UINavigationController alloc]initWithRootViewController:tab];
}
当我使用
nav=[[UINavigationController alloc]initWithRootViewController:news]时

我得到的输出是这样的

当我使用
nav=[[UINavigationController alloc]initWithRootViewController:tab]时

我需要像这样同时调用uitabar控制器和UINavigationBar控制器

我也使用了这样的代码

ViewConroller1 *login = [[ViewConroller1 alloc] initWithNibName:@"ViewConroller1" bundle:nil];
    AppDelegate *appDelegate = [UIApplication sharedApplication].delegate;
    [appDelegate.window setRootViewController:appDelegate.tab];
    [self.navigationController pushViewController:login animated:YES];
但什么也没发生


那么如何做到这一点。提前谢谢

在else条件下将tabBarController设置为窗口的根,以使tabBarController和导航控制器嵌入其中

        if ([Userid isEqualToString:@"null"]) {
             Hard =[[HardSoftScreen alloc] initWithNibName:@"HardSoftScreen" bundle:nil];
             nav = [[UINavigationController alloc]initWithRootViewController:Hard];
             [self.window setRootViewController:nav];
        }
        else
        {
            [self.window setRootViewController:tab];
            [self.window makeKeyAndVisible];
        }

它正在展示黑色的窗户。我还需要调用else块中的viewcontroller1 viewcontroller1是选项卡栏上的第一个选项卡,因此如果选择tab作为根,它将显示出来。请添加didFinishLaunchingWithOptions方法的完整代码,以获得清晰的想法。我正在检查,如果userid=null,则将显示硬软屏viewController,否则将显示viewcontroller1。硬软屏是没有导航的简单视图,选项卡栏和viewcontroller1都包含。是否使用self.window.rootViewController=else条件后的导航?