gpt4 book ai didi

ios - 如何从 "Empty Application"模板制作通用应用程序?

转载 作者:行者123 更新时间:2023-11-29 04:48:20 25 4
gpt4 key购买 nike

我尝试重写一些旧的应用程序,并想从头开始。

基本上,我尝试从“空应用程序”模板开始,这只会给我留下一个 AppDelegate.m/.h,我需要在 iPad/iPhone 之间进行自己的分离。

知道如何在 AppDelegate 中执行此操作吗?

在较旧的 Xcode 版本中,程序为 iPad/iPhone 创建单独的委托(delegate)。

最佳答案

当您必须对 iPhone 和 iPad 进行不同的处理时,您可以使用以下方法来查看您使用的是哪一种:

if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
// Do things for iPad
} else {
// Do things for iPhone
}

因此,您可以为 iPad 或 iPhone 使用不同的 View 委托(delegate),或者如果它们的行为几乎相同,您可以使用相同的 View 委托(delegate)并在必要时使用之前的测试。例如,您可以修改 init 方法来加载不同的 Xib 文件:

- (id)init
{
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
self = [super initWithNibName:@"ViewController_iPad" bundle:nil];
} else {
self = [super initWithNibName:@"ViewController_iPhone" bundle:nil];
}
if (self) {
// Custom initialization
}
return self;
}

您可以在 shouldAutorotateToInterfaceOrientation 等中执行类似的操作。

关于ios - 如何从 "Empty Application"模板制作通用应用程序?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9279504/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com