我可以创建的RootViewController,AppDelegate和View Controller类之间有什么区别? [英] What's the difference between the RootViewController, AppDelegate and the View Controller classes that I may create?

查看:152
本文介绍了我可以创建的RootViewController,AppDelegate和View Controller类之间有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试学习编程的iPhone,我不断看到这些文件,我不知道每个文件和这些文件的内容,在执行一个程序为iPhone构建的时候。我试图遵循教程和提示在线,但没有地方有一个点对点的比较或类似的东西。如果你能列出一些基本的差异,如何时每个文件被引用和什么应该理想地进入每个文件等等,这将是巨大的。感谢您的时间。

解决方案

一般来说,代表可以被认为是事件处理程序。因此,AppDelegate是整个应用程序的主要事件处理程序。它被告知当应用程序启动时,当它将退出,当推送通知进来,当应用程序进入后台等等。其中一个事件 - applicationDidFinishLaunching - 通常负责创建应用程序的窗口和添加视图



在大多数应用程序中,添加到窗口的视图实际上由UIViewController控制。每个UIViewController负责管理一个主视图及其所有子视图的外观。例如,UITableViewController负责管理插入到UITableView中的UITableView(主视图)和所有UITableViewCells(子视图)。 UIViewController通常作为一个委托(事件处理程序)对它负责的视图。当用户点击表视图单元格时,会调用UITableViewController中的一个方法。当用户滑动以删除单独的方法时调用。



通用UIViewController提供相同的基本功能,但是提供自定义视图。例如,UIViewController可能负责显示几个文本视图和一个按钮。 UIViewController将创建其主视图,文本视图和按钮视图。文本视图和按钮视图将作为子视图添加到视图控制器的主视图中。 UIViewController将自己注册为来自文本视图的事件的委托(例如,当用户在文本视图中完成编辑文本时学习)。它还将注册一种方法来处理源自其拥有的按钮的按钮按钮。当任何这些注册的事件发生时,UIViewController上的方法被调用允许你采取任何需要的操作。



rootViewController是一个特定类型的视图控制器与导航控制器。如果你想要有一个典型的iOS导航视图层次结构的应用程序,你的AppDelegate通常会添加一个UINavigationController到应用程序的窗口。 UINavigationController没有实际上没有内容显示是无用的。这就是rootViewController的作用。你负责提供一个视图控制器(如上面描述的)来作为存储在UINavigationController的视图堆栈中的第一个视图。该视图将在应用程序启动时显示,并在用户从UINavigationController的堆栈中弹出后续的ViewControllers时显示。



很长时间我意识到 - 但希望它有所帮助。 / p>

I am trying to learn programming for the iPhone and I keep seeing these files and I am not sure when is each file and content of those files referred to in the execution of a program built for the iPhone. I am trying to follow tutorials and tips available online but nowhere is there a point by point comparison or something like that. It would be great if any of you could list a few basic differences like when is each file referred and what should ideally go into each file and so on. Thanks for your time already.

解决方案

In general, delegates can be thought of as event handlers. Accordingly, the AppDelegate is the main event handler for your entire application. It is told when the application has launched, when it will exit, when a Push notification comes in, when the app has gone into the background, etc. One of those events - applicationDidFinishLaunching - is typically responsible for creating the application's window and adding views to that window.

In most applications, the view that is added to the window is actually controlled by a UIViewController. Each UIViewController is responsible for managing the appearance of one main view plus all of its subviews. For example, a UITableViewController is responsible for managing a UITableView (main view) and all of the UITableViewCells (subview) that are inserted into that UITableView. The UIViewController typically acts as a delegate (event handler) to the views it is responsible for. When a user taps a table view cell, a method in the UITableViewController is called. When the user swipes to delete a separate method is called.

A generic UIViewController provides the same basic functionality, but for custom views. For example, the UIViewController may be responsible for displaying a few text views and a button. The UIViewController would create its main view, the text views and the button view. The text views and button view would be added to the view controller's main view as subviews. The UIViewController would register itself as the delegate for events from the text view (for example learning when the user has finished editing the text in the text view). It would also register a method to handle a button press originating from the button it owned. When any of these registered events occur, methods on the UIViewController are called allowing you to take whatever action is needed.

The rootViewController is a specific type of view controller used with navigation controllers. If you want an application that has the typical iOS navigation view hierarchy, your AppDelegate would typically add a UINavigationController to the app's window. That UINavigationController is useless without actually having content to display. That is where the rootViewController comes into play. You are responsible for providing a view controller (such as the one described above) to act as the first view stored in the UINavigationController's stack of views. This view will be displayed when the app starts up and anytime that the user pops subsequent ViewControllers off of the UINavigationController's stack.

Long winded I realize - but hope it helps.

这篇关于我可以创建的RootViewController,AppDelegate和View Controller类之间有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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