iPad模拟器/设备使用iPhone故事板

5
所以我已经为iPhone创建了一个应用程序,我想将其转换为iPad,按照此答案的步骤进行:answer
  • 复制您的iPhone故事板并将其重命名为MainStoryboard_iPad.storyboard

  • 使用任何文本编辑器打开此文件。

  • 搜索targetRuntime="iOS.CocoaTouch"并将其更改为targetRuntime="iOS.CocoaTouch.iPad"

  • 现在保存所有内容并重新打开Xcode -> iPad-Storyboard包含与iPhone文件相同的内容,但可能会被打乱

一切都做得正确,但iPad模拟器/设备无论如何都使用iPhone storyboard。有什么建议吗?
我在摘要-> ipad部署信息->主故事板中设置了iPad故事板。 main.plist-> Main storyboard file base name (iPad)设置为iPad故事板。
请告诉我我错过了什么。
UPD. 有趣的事情是,当我从iPad部署信息中删除iPad故事板名称时,它仍然在设备上使用我的iPhone故事板。

Xcode使用iPhone故事板是什么意思?当您构建iPad模拟器时,它仍然使用iPhone故事板吗? - danielrsmith
是的,iPad模拟器/设备使用iPhone模拟器。 - Vlad Z.
1
在iOS应用程序目标下,设备设置为通用吗? - danielrsmith
是的,应用程序目标已设置为通用。 - Vlad Z.
2个回答

4
你可以在appDelegate中选择合适的故事板,并以编程方式呈现相应的根视图控制器。
@interface AppDelegate : UIResponder <UIApplicationDelegate>
{
    UIViewController *rvc;
}

实现

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
    if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
       UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"IPAD_Storyboard" bundle:nil];
       rvc = [storyboard instantiateViewControllerWithIdentifier:@"identifierForController"];
    }
    else {
       UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Storyboard" bundle:nil];
       rvc = [storyboard instantiateViewControllerWithIdentifier:@"identifierForController"];
    }


    [self.window addSubview:rvc.view];
    self.window.backgroundColor = [UIColor whiteColor];
    [self.window makeKeyAndVisible];

    return YES;
}

不是最符合Xcode的方式,但你似乎在那条路上遇到了问题:/,很高兴我能帮忙。 - j_mcnally
这已经过时了。请将addSubview行替换为:[self.window setRootViewController:rvc]; - galactikuh

4

不要忘记在项目的info.plist文件中添加以下内容(主故事板文件基本名称/主故事板文件基本名称(iPad))

输入图像描述

希望这能有所帮助。


是的,info->主故事板文件基本名称(iPad)已设置为iPad故事板。 - Vlad Z.
这正是我的问题。当我将应用程序升级为通用应用程序时,Xcode将主nib文件基本名称(iPad)设置为Main-iPad.storyboard,而不是正确的主storyboard文件基本名称(iPad)。 - Dustin

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接