有人可以帮我了解什么是这个“代表”? [英] Can Someone Help Me To Understand What Is This "Delegate"?

查看:130
本文介绍了有人可以帮我了解什么是这个“代表”?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在学习Objective-C,而我必须做一个应用程序。我想要做的是从代码中的 MainViewController ,一个 SplitViewController 调用。已经解决了现在,我必须调用多个 DetailViewController 。我发现了这个例子: http://kshitizghimire.com .np / uisplitviewcontroller-multipledetailviews-with-navigation-controller /


我这个例子,他们使用 MultipleDetailViewsWithNavigatorAppDelegate 声明 SplitViewController MasterViewController ,因为 SplitViewController 从开始,在第一个 ViewController 中,并使用 AppDelegate c $ c> didFinishLaunching / code>。在我的应用程序中,我正在第二个 ViewController 中加载 SplitViewController ,所以我的 SplitViewController 在我的 ViewController 中声明并加载,而不是在我的 AppDelegate 中。我已经阅读过,代理就像 Interfaces ,以不同的方式声明和实现方法,但是这里没有使用协议或委托方法。所以,我必须为我的 SecondViewController 执行其他 AppDelegate ,并在这个新的 AppDelegate中声明 SplitViewController MasterViewControler ?或者是这个 AppDelegate 变量引用,只是引用 SplitViewController



谢谢

解决方案

可可核心竞争力


委托是一种简单而强大的模式,其中
程序中的一个对象代表另一个对象或与另一个对象协调工作。
委托对象保留对其他对象的引用 -
委托 - 并在适当的时候向其发送消息。
消息通知委托一个事件,委托对象是
即将处理或刚刚处理。代理人可以通过更新应用程序中其自身或其他对象
的外观或状态来响应
消息,在某些情况下,它可以返回一个值,
会影响即将发生的事件处理。
委托的主要价值在于它允许您轻松自定义一个中心对象中的
几个对象的行为。



I'm learning Objective-C, and I have to do one app. What I'm trying to do, is call from my MainViewController, a SplitViewController, in code. That's already solved. Now, I have to call multiple DetailViewControllers. I've found this example:
http://kshitizghimire.com.np/uisplitviewcontroller-multipledetailviews-with-navigation-controller/

I this example, they use MultipleDetailViewsWithNavigatorAppDelegate to declare SplitViewController and MasterViewController, because the SplitViewController is loaded from the start, in the first ViewController, and using the didFinishLaunching function, of the AppDelegate. In my app, I'm loading the SplitViewController in the second ViewController, so my SplitViewController is declared and loaded in my ViewController, not in my AppDelegate. I've read, that "delegates" are like Interfaces, to declare and implement methods in different way, but here there are not using protocols or delegate methods. So, I have to do other AppDelegate for my SecondViewController, and declare in this new AppDelegate the SplitViewController and MasterViewControler?... Or is this AppDelegate variable reference, just to reference to SplitViewController?

Thanks

解决方案

From Cocoa Core Competencies:

Delegation is a simple and powerful pattern in which one object in a program acts on behalf of, or in coordination with, another object. The delegating object keeps a reference to the other object—the delegate—and at the appropriate time sends a message to it. The message informs the delegate of an event that the delegating object is about to handle or has just handled. The delegate may respond to the message by updating the appearance or state of itself or other objects in the application, and in some cases it can return a value that affects how an impending event is handled. The main value of delegation is that it allows you to easily customize the behavior of several objects in one central object.

这篇关于有人可以帮我了解什么是这个“代表”?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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