【问题标题】:How to set a starting viewcontroller.xib in iOS using objective c如何使用objective c在iOS中设置起始viewcontroller.xib
【发布时间】:2015-11-12 16:17:17
【问题描述】:

我是 iOS 新手。我创建了一个单视图应用程序。它有一个视图控制器。编译应用程序时,它会显示我的视图控制器的全黑颜色。现在我需要的是如何将我的视图控制器初始化为第一个视图控制器以及我需要初始化我的应用程序的导航控制器。注意:我创建了 xib 视图控制器。

【问题讨论】:

    标签: ios objective-c uinavigationcontroller xib appdelegate


    【解决方案1】:

    在 AppDelegate.m 中

    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    // Override point for customization after application launch.
    self.window = [[UIWindow alloc]initWithFrame:[[UIScreen mainScreen] bounds]];
    HomeViewController *homeVc = [[HomeViewController alloc]initWithNibName:@"HomeViewController" bundle:nil];
    UINavigationController *nav = [[UINavigationController alloc]initWithRootViewController:homeVc];
    self.window.rootViewController = nav;
    [self.window makeKeyAndVisible];
    return YES;
    }
    

    【讨论】:

      【解决方案2】:

      打开 ViewController.xib。选择文件的所有者占位符。打开 Identity Inspector 并将类更改为 ViewController。

      打开 Connections Inspector 并连接 view outlet。

      更新 AppDelegate。

      AppDelegate.h

      #import <UIKit/UIKit.h>
      #import "ViewController.h"
      
      @interface AppDelegate : UIResponder <UIApplicationDelegate>
      @property (strong, nonatomic) UIWindow *window;
      @property (strong, nonatomic) ViewController *viewController;
      @end
      

      AppDelegate.m

      @implementation AppDelegate
      
      - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
      {
          self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
          // Override point for customization after application launch.
          self.viewController = [[ViewController alloc] initWithNibName:@"ViewController" bundle:nil];
          UINavigationController *nav = [[UINavigationController alloc]initWithRootViewController:self.viewController];
          self.window.rootViewController = nav;
          [self.window makeKeyAndVisible];
          return YES;
      }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2015-03-19
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多