3

我的模拟器有点奇怪,我希望有人能帮助我。下面的代码在我的 AppDelegate 中。根据正在运行的设备,我有不同的故事板。设备检测代码似乎工作正常,但我在将模拟器硬件 - >设备保持在我想要的位置时遇到问题。

  1. 项目设置为“通用”,模拟器设置为 iPhone。模拟器将自己更改为 iPhone 模拟器并作为 iPhone 运行。
  2. 项目设置到 iPad,模拟器到 iPad,作为 iPad 运行。将项目设置回通用,模拟器设置回 iPhone,模拟器将自身重置回 iPad 并将代码作为 iPad 运行。
  3. 项目设置为 iPhone,将模拟器留在 iPad 上。在 iPad 上作为 iPhone 应用程序运行??

....以及多种不同的变体。尝试多次重启Mac和xcode,没有效果。如果我重置模拟器并在模拟器上而不是通过 xcode 运行项目图标,模拟器将保持在我放入的硬件模式下。有什么想法吗?


-(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    // testing for iPad detection
    if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
    {
        // setting storyboard name
        [[Data sharedData] setStoryboardName:@"MainStoryboardPad"];

        // going to the 4" screen story board and settng it as the root controller
        self.window = [[UIWindow alloc] initWithFrame:UIScreen.mainScreen.bounds];
        UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboardPad" bundle:nil];
        UIViewController *viewController = [storyboard instantiateViewControllerWithIdentifier:@"Intro Screen"];

        // making that tab controller the root controller
        self.window.rootViewController = viewController;
        [self.window makeKeyAndVisible];
        return YES;
    }
    else
    {
        // detecting screen size
        if (([UIScreen mainScreen].scale == 2) && ([[UIScreen mainScreen] bounds].size.height == 568))
        {
            // setting storyboard name
            [[Data sharedData] setStoryboardName:@"MainStoryboard40"];

            // going to the 4" screen story board and settng it as the root controller
            self.window = [[UIWindow alloc] initWithFrame:UIScreen.mainScreen.bounds];
            UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard40" bundle:nil];
            UIViewController *viewController = [storyboard instantiateViewControllerWithIdentifier:@"Intro Screen"];

            // making that tab controller the root controller
            self.window.rootViewController = viewController;
            [self.window makeKeyAndVisible];
            return YES;
        }
        else
        {
            // setting storyboard name
            [[Data sharedData] setStoryboardName:@"MainStoryboard35"];

            // going to the 3.5" screen story board and settng it as the root controller
            self.window = [[UIWindow alloc] initWithFrame:UIScreen.mainScreen.bounds];
            UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard35" bundle:nil];
            UIViewController *viewController = [storyboard instantiateViewControllerWithIdentifier:@"Intro Screen"];

            // making that tab controller the root controller
            self.window.rootViewController = viewController;
            [self.window makeKeyAndVisible];
            return YES;
        }
    }
}
4

1 回答 1

1

如果我正确理解了您的问题,那么您遇到的问题是您在模拟器中作为 iPad 运行您的应用程序时遇到了困难,因为它不断变回 iPhone。这是因为您需要在 Xcode 的顶部工具栏中选择要在哪个模拟器中运行应用程序:

点击菜单

选择您要运行的模拟器

之后,单击运行,您选择的 iOS 模拟器应该会打开并运行您的应用程序。

于 2013-05-11T03:25:20.673 回答