Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/95.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 如何从appdelegate显示UIViewConcoller_Ios_Objective C_Uinavigationcontroller_Uitabbarcontroller_Appdelegate - Fatal编程技术网

Ios 如何从appdelegate显示UIViewConcoller

Ios 如何从appdelegate显示UIViewConcoller,ios,objective-c,uinavigationcontroller,uitabbarcontroller,appdelegate,Ios,Objective C,Uinavigationcontroller,Uitabbarcontroller,Appdelegate,我正在使用UIAbbarOnToller(带有5个UIViewController)和uinavigation bar开发一个应用程序。 我已经在应用程序中创建了所有这些,但当我运行它时,它不起作用 这是AppDelegate.m类: - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { UINavigationContr

我正在使用UIAbbarOnToller(带有5个UIViewController)和uinavigation bar开发一个应用程序。 我已经在应用程序中创建了所有这些,但当我运行它时,它不起作用

这是AppDelegate.m类:

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

    HomePageView *viewController = [[HomePageView alloc] init];
    FeedViewController *feedViewController=[[FeedViewController alloc]init];
    ProfileViewController *profileViewController=[[ProfileViewController alloc]init];
    PlayViewController *playViewController = [[PlayViewController alloc]init];
    ListeningSessionViewController *listeningSessionViewController= [[ListeningSessionViewController alloc]init];
    RecievedViewController *recievedViewController =[[RecievedViewController alloc]init];

    tabBarController.viewControllers=[NSArray arrayWithObjects:feedViewController,profileViewController,playViewController,listeningSessionViewController,recievedViewController, nil];

    //navigating to the UITabBarController that you created
    [navCon pushViewController:tabBarController animated:YES];
    [navCon pushViewController:viewController animated:NO];

    return YES;
}
.h

@property (strong, nonatomic) UIWindow *window;
@property (strong, nonatomic) UINavigationController *navC;
@property (strong, nonatomic) UITabBarController *tabC;
.m中的
appdidfish

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

// Initialize your five tab controllers.  with each tab has its own navigation controller
FeedViewController *feedViewController=[[FeedViewController alloc]init];
UINavigationController *nav1 = [[UINavigationController alloc]initWithRootViewController:feedViewController];

ProfileViewController *profileViewController=[[ProfileViewController alloc]init];
UINavigationController *nav2 = [[UINavigationController alloc]initWithRootViewController:profileViewController];

PlayViewController *playViewController = [[PlayViewController alloc]init];
UINavigationController *nav3 = [[UINavigationController alloc]initWithRootViewController:playViewController];

ListeningSessionViewController *listeningSessionViewController= [[ListeningSessionViewController alloc]init];
UINavigationController *nav4 = [[UINavigationController alloc]initWithRootViewController:listeningSessionViewController];

RecievedViewController *recievedViewController =[[RecievedViewController alloc]init];
UINavigationController *nav5 = [[UINavigationController alloc]initWithRootViewController:recievedViewController];

// initialize tabbarcontroller and set your viewcontrollers.
self.tabC = [[UITabBarController alloc]init];
self.tabC.viewControllers=[NSArray arrayWithObjects:nav1,nav2,nav3,nav4,nav5, nil];

// Inititalize Navigationcontroller and set root as tabbar.
self.navC = [[UINavigationController alloc]initWithRootViewController:self.tabC];

// Set Window rootview as navigation.
self.window.rootViewController = self.navC;

// Show window
[self.window makeKeyAndVisible];

这可能会对您有所帮助。

Main.storyBoard
中实例化一个
UITabBarController
,并将其连接到identity inspector中的类
tabBarCon

接口:

@interface tabBarCon: UITabBarController

@end
实施:

@implementation tabBarCon

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization

    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];

   // Do any additional setup after loading the view.

   HomePageView *viewController = [[HomePageView alloc] init];
   FeedViewController *feedViewController=[[FeedViewController alloc]init];
   ProfileViewController *profileViewController=[[ProfileViewController alloc]init];
   PlayViewController *playViewController = [[PlayViewController alloc]init];
   ListeningSessionViewController *listeningSessionViewController= [[ListeningSessionViewController alloc]init];
   RecievedViewController *recievedViewController =[[RecievedViewController alloc]init];


        NSArray *viewControllerArray = [[NSArray alloc]initWithObjects:viewController,
                                                                       feedViewController,
                                                                       profileViewController,
                                                                       playViewController,
                                                                       listeningSessionViewController,
                                                                        recievedViewController,nil];

//Then add buttons
 UITabBarItem *moreItem = [[UITabBarItem alloc]initWithTabBarSystemItem:UITabBarSystemItemMore tag:0];
 viewController.tabBarItem = moreItem;
//...


 self.viewControllers = viewControllerArray;


}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end

为什么要将选项卡栏控制器推到导航控制器上?根据需要,每个选项卡都应该有自己的导航控制器。@rmaddy我删除了该行,但它仍然不工作。“不工作”是开发人员可以使用的最无用的词。这是毫无意义的。请更新您的问题,详细说明您希望发生的事情,并解释实际发生的事情。具体点。我看不到你在任何地方将tabBarController添加到窗口。尝试用
self.window.rootViewController=tabBarController
替换
return YES
之前的最后两行,我是否可以让tabbar项目同时显示?因为在我设置了所有项目之后,当我运行时,只会显示第一个项目标题。因此,如果要显示其他Tabbaritem,我必须单击每个选项卡才能看到下面的标题。那么,列出所有Tabbaritem的应用程序呢?你不必单击每个选项卡,然后它会在下面显示标题,它在应用程序首次加载时已经存在。你明白我的意思吗?