将 App Delegate 连接到控制器类 [英] Connecting App Delegate to Controller Class

查看:45
本文介绍了将 App Delegate 连接到控制器类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我被困在开发 XCode 应用程序的这一步:,因为我还没有't想出了如何把一切都联系起来.

为了重新解释,我需要弄清楚 AppDelegate 和 TrackController 如何相互关联和通信.这些概念对我来说通常是新的,我已经阅读了 Apple 文档,但它们并没有真正帮助我.我什至与专家进行了深入讨论,但我仍然不明白它应该如何工作.

我的模型是 Track,然后我有 TrackController,当然还有 AppDelegate.AppDelegate 正在实例化 TrackController,我希望它能够打开它的窗口.

我做错了什么?希望高手帮帮我!

解决方案

它描述的是应用程序委托应该专注于处理发送到应用程序的委托调用.

您实际上创建了一个新类来充当应用程序的主控制器,然后添加代码以在应用程序加载完成时调用它.从那时起,该应用(据说)就是您的主要控制点(当然,当它交出"给另一个班级时除外).

与 Mac 相比,我更熟悉 iOS 上的流程如何工作,Mac 需要担心 Windows,但对于 iOS 应用,您需要添加代码以从 ApplicationDidFinishLaunching:WithOptions: 内部调用起始视图控制器.从那里,视图控制器起飞,查看整个过程的最简单方法是从视图控制器开始(这是大多数教程处理它的方式,事实上,让 XCode 处理应用程序委托创建该视图控制器的事实).

I'm stuck on this step of developing an XCode application: https://developer.apple.com/library/mac/#documentation/General/Conceptual/Mac101/Articles/07_WhereNext.html

What I'm confused about is the role of the AppDelegate class that's created by default when creating a project initially in XCode 4. If I implement a custom controller, let's use the example link above and call it TrackController. Do I make that controller the app delegate? It seems any tutorial I read isn't very clear on this.

So, in AppDelegate, do I create a new instance of the controller class here? And if so, do I then hook up the outlet here? Or do I change the File's Owner to be the controller class? If that's the case, then how's that done in XCode 4?

Not a very well defined question I know, but I'm sure someone knows what I'm talking about.

EDIT

The following screenshot shows what I mean. The blue box is now "Track Controller". I've shown the AppDelegate class in this case though to make it clear. What do I use, AppDelegate.m, or TrackController.m? How should it be done?

EDIT 2

Going back to this, I've uploaded the code to GitHub here as I still haven't figured out how to hook everything up.

To re-explain, I need to figure out how AppDelegate and TrackController all relate and communicate with one another. The concepts are generally new to me and I've read the Apple documentation but they haven't really helped me. I've even had in-depth discussions with experts and I still fail to see how it should work.

My model is Track, then I have TrackController and of course AppDelegate. AppDelegate is instantiating TrackController and I was hoping that it'd be able to open up its window.

What am I doing wrong? Hopefully an expert can help me!

解决方案

What it's describing is that the application delegate should focus on handling the delegate calls sent to the app.

You actually create a new class to act as the primary controller of the app, and then you add code to call it when the app is finished loading. From there on out, that app is (supposedly) your primary control point (except, of course, when it 'hands off' to another class).

I'm more familiar with how the process works on iOS than Macs, which have to worry about windows, but for an iOS app you'd add code to call your starting view controller from inside ApplicationDidFinishLaunching:WithOptions:. From there, the view controller takes off, and the easiest way to view the entire process is that you start at the view controller (that's how most tutorials handle it, in fact, letting XCode handle the fact that the app delegate creates that view controller).

这篇关于将 App Delegate 连接到控制器类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆