Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/39.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/27.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
Iphone 我想实现TabBarController并添加导航控制器视图,但没有成功_Iphone_Objective C_Uinavigationcontroller_Uitabbarcontroller_Tabbar - Fatal编程技术网

Iphone 我想实现TabBarController并添加导航控制器视图,但没有成功

Iphone 我想实现TabBarController并添加导航控制器视图,但没有成功,iphone,objective-c,uinavigationcontroller,uitabbarcontroller,tabbar,Iphone,Objective C,Uinavigationcontroller,Uitabbarcontroller,Tabbar,我知道如何通过Interface Builder添加带有两个TabBar按钮的TabBar。我将每个按钮链接到导航控制器 现在我想学习如何以编程的方式做每件事。现在我可以在模拟器中看到一个选项卡栏,但上面没有按钮。谁能帮我一下吗。谢谢 这是TabBarAppDelegate.h #import <UIKit/UIKit.h> @interface TabBarAppDelegate : NSObject <UIApplicationDelegate> { UIW

我知道如何通过Interface Builder添加带有两个TabBar按钮的TabBar。我将每个按钮链接到导航控制器

现在我想学习如何以编程的方式做每件事。现在我可以在模拟器中看到一个选项卡栏,但上面没有按钮。谁能帮我一下吗。谢谢

这是TabBarAppDelegate.h

#import <UIKit/UIKit.h>
@interface TabBarAppDelegate : NSObject <UIApplicationDelegate> 
{
    UIWindow *window;
    UITabBarController *tabBarController;
    IBOutlet UINavigationController *navigationController1;
    IBOutlet UINavigationController *navigationController2;
}

@property (nonatomic, retain) IBOutlet UIWindow *window;
@property (nonatomic, retain) UITabBarController *tabBarController;
@property (nonatomic, retain) IBOutlet UINavigationController *navigationController1;
@property (nonatomic, retain) IBOutlet UINavigationController *navigationController2;
@end

看起来您没有初始化导航视图控制器。看看这是否可行:

TabBarAppDelegate.h

  • 删除属性navigationController1和navigationController2
TabBarAppDelegate.m

  • 替换

    [self.navigationController1 pushViewController:firstViewController animated:NO];
    
    [self.navigationController2 pushViewController:secondViewController animated:NO];
    

  • 替换

    [self.navigationController1 pushViewController:firstViewController animated:NO];
    
    [self.navigationController2 pushViewController:secondViewController animated:NO];
    

  • 将navigationController1和navigationController2添加到tabBarController后,释放它们

谢谢您的回复。但是这样,navigationController1和navigationController2将在AppDelegate.m之外过期。如果我仍然想将另一个视图推送到FirstViewController,该怎么办?要将另一个视图推送到FirstViewController,在FirstViewController中,您可以使用[self.navigationController pushViewController:animated:]我现在完全明白了。非常感谢你。
UINavigationController *navigationController2 = [[UINavigationController alloc] initWithRootViewController:secondViewController];