gpt4 book ai didi

iphone - 带有 Xcode 4.2 的 Interface Builder 中的 UIApplicationDelegate

转载 作者:可可西里 更新时间:2023-11-01 05:15:29 25 4
gpt4 key购买 nike

我的应用程序是一个基于 View 的应用程序。我需要创建一个 UINavigationController 作为我的 rootViewController

在之前版本的 Xcode 中,有一个名为 mainWindow 的 xib 文件,我们可以在其中:

  • 将我们的UIApplicationDelegate 实现连接到UIApplicationdelegate 导出
  • UIWindow 连接到 UIApplicationDelegate
  • UIViewController 连接到 UIWindowrootViewController 属性。

但是现在(Xcode 4.2)不会创建这个 xib 文件!

那么我如何创建自定义 UINavigationController 并将其连接到我在 InterfaceBuilder 中的 UIApplicationDelegate 实现?

这是我在 UIApplicationDelegate 实现中的代码:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
SDWebImageRootViewController *root = [[SDWebImageRootViewController alloc] initWithNibName:nil bundle:nil];

_navigationController = [[[UINavigationController alloc] initWithRootViewController:root] autorelease];

self.window.rootViewController = _navigationController;

[[_navigationController navigationBar] setBarStyle:UIBarStyleBlack];
[[_navigationController navigationBar] setTranslucent:YES];

[_window addSubview:[_navigationController view]];
}

最佳答案

首先,是的,即使在最新版本的 Xcode 中,您仍然可以为此使用 IB,所以我不确定您从哪里得到它。

如果您想知道如何在没有 IB 的情况下指定您的应用程序委托(delegate),那非常简单:

在您的 main 方法中,只需使用您的应用程序委托(delegate)的类名作为 UIApplicationMain 的第四个参数:

int main(int argc, char *argv[])
{
@autoreleasepool
{
int retVal = UIApplicationMain(argc, argv, nil, @"APPLICATION_DELEGATE_CLASS_NAME");
return retVal;
}
}

事实上,当您从模板创建基于 View 的应用程序时,Xcode 4.2 默认会为您执行此操作(尽管它不使用静态字符串...老实说,这可能比我的建议更好,因为它会得到如果您使用内置重构等,则重构):

NSStringFromClass([AppDelegate 类])

回答您的后续问题:好的,那我该怎么办?在接口(interface)中连接 UINC socket ?

别打扰了。

还是不相信我?很好...这是一个教程...它是十五个步骤! ...而且完全没有意义。

首先,创建应用程序:

enter image description here

打开main.m并将第四个参数替换为nil:

enter image description here

创建一个新的 xib,或者劫持现有的(我将在这里做),并使文件的所有者类 UIApplication

enter image description here

接下来,从工具箱中添加一个 Object 并将类更改为您的 UIApplicationDelegate 子类:

enter image description here

现在,切换回文件所有者并将 delegate 导出连接到您添加的 UIApplicationDelegate。如果你正在做我所做的并劫持了现有的 xib,请删除 view 引用。

enter image description here

现在从工具箱中添加一个UIWindow

enter image description here

现在从工具箱中添加一个“UIViewController”。这是您的自定义UIViewController。如果您想要一个UINavigationControllerUITableViewController`,只需添加它即可。

enter image description here

如果使用自定义 UIViewController 类,请在此处指定类:

enter image description here

UIWindowrootViewController socket 连接到您的 UIViewController:

enter image description here

打开您的UIApplicationDelegate 界面,创建或修改window 属性,使其成为IBOutlet

enter image description here

切换到实现并删除任何设置窗口和 Root View Controller 的“无值(value)”代码。 (我在这里是在讽刺......这段简洁的代码完成了我们在这里所做的一切......只是以编程方式而不是通过 IB。)

enter image description here

切换回您的 xib 并连接您的 UIApplicationDelegatewindow socket 。

enter image description here

现在,在目标的部署信息中,将 xib 设置为“主界面”:

enter image description here

完成....呸!

关于iphone - 带有 Xcode 4.2 的 Interface Builder 中的 UIApplicationDelegate,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8781488/

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