【问题标题】:MainWindow-iPad.xib in xcode 4.6.3 [closed]xcode 4.6.3 中的 MainWindow-iPad.xib [关闭]
【发布时间】:2013-08-16 13:46:19
【问题描述】:

现在我正在阅读 Head First iPhone and iPad Development 2nd edition (Dan Pilone, Tracey Pilone) 一书。而当,根据书中的练习,我需要将书中的程序从iphone更改为universal时,xcode正在自动制作MainWindow-iPad.xib,但我的xcode没有。书中的一开始程序也有文件 MainWindow.xib,但我没有。我现在该怎么办?如果我要更改 MasterViewController.xib(导航模板),更改也将在 iPhone 模拟器版本中。

【问题讨论】:

    标签: iphone ios objective-c xcode ipad


    【解决方案1】:

    根据您的评论重新表述您的问题:

    如果smb要做一个通用程序,而ipad和iPhone上的xibs需要不同,怎么办?

    您在 appDelegate 中执行此操作:

    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
    {
        self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
        // Override point for customization after application launch.
        if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
            self.viewController = [[HWViewController alloc] initWithNibName:@"HWViewController_iPhone" bundle:nil];
        } else {
            self.viewController = [[HWViewController alloc] initWithNibName:@"HWViewController_iPad" bundle:nil];
        }
        self.window.rootViewController = self.viewController;
        [self.window makeKeyAndVisible];
        return YES;
    }
    

    该代码直接取自 XCode 中的单一视图模板 - 但无论有无模板,该代码均有效。

    假设您有两个单独的 xib 文件,一个名为“HWViewController_iPhone.xib”,另一个名为“HWViewController_iPad.xib”。只要名称与代码中的initWithNibName: 字符串一致(您在代码中省略了“.xib”),名称就无关紧要了。

    您可以在 XCode 中使用 New > File > User Interface > View 制作 xib 文件

    【讨论】:

    • 现在我在 Appdelegate.m 中有这段代码
    【解决方案2】:

    您的书已过期。您可以通过添加 xib 并将其设置为目标摘要中部署信息中的主界面来执行该路由。

    真的,虽然没有什么理由这样做。更好的方法是创建一个根视图控制器并在您的应用委托中进行设置。

    RootViewController *rootViewController = [[RootViewController alloc] init];
    self.window.rootViewController = rootViewController;
    [self.window makeKeyAndVisible];
    

    【讨论】:

      【解决方案3】:

      现在我在 Appdelegate.m 中有这段代码:

      - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
      {
          self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
          // Override point for customization after application launch.
          if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
              self.viewController = [[UIViewController alloc] initWithNibName:@"HWViewController_iPhone" bundle:nil];
          } else {
              self.viewController = [[UIViewController alloc] initWithNibName:@"HWViewController_iPad" bundle:nil];
          }
          self.window.rootViewController = self.viewController;
          [self.window makeKeyAndVisible];
          return YES;
          MasterViewController *masterViewController = [[MasterViewController alloc] initWithNibName:@"MasterViewController" bundle:nil];
          self.navigationController = [[UINavigationController alloc] initWithRootViewController:masterViewController];
          self.window.rootViewController = self.navigationController;
          [self.window makeKeyAndVisible];
          return YES;
      }
      

      还有 3 个错误:在“AppDelegate *”类型的对象上找不到属性“viewController” 在这个字符串之后:

      self.viewController = [[UIViewController alloc] initWithNibName:@"HWViewController_iPhone" bundle:nil];
      self.viewController = [[UIViewController alloc] initWithNibName:@"HWViewController_iPad" bundle:nil];
      self.window.rootViewController = self.viewController;
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2013-06-14
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多