Objective-C对象可以是自己的代理吗?是好的编程实践吗? [英] Can an Objective-C object be its own delegate? Is it good programming practice?

查看:110
本文介绍了Objective-C对象可以是自己的代理吗?是好的编程实践吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道这是可能的,但它是真的很好的编程实践吗?想法是子类 UIAlertView 并且订阅自己作为我自己的代理,以便能够添加按钮和阻止处理程序。这样,当我得到 alertView:clickedButtonAtIndex:我调用传递的块。

I know it is possible, but is it really a good programming practice? The idea is to subclass UIAlertView and subscribe myself as my own delegate in order to be able to add buttons and block handlers. That way, when I get the alertView:clickedButtonAtIndex: I call the block that was passed on.

这是可以理解的。这是一个好的编程实践吗?

I hope it's understandable. Is it a good programming practice?

更新:这里是我的想法,我问的是什么 https://github.com/ianmurrays/IMAlertView

UPDATE: Here's my idea of what I was asking https://github.com/ianmurrays/IMAlertView. Any comments would be greatly appreciated.

推荐答案

是的,任何类或对象都可以是任何其他的委托,甚至是本身。但我会说这不是一个好的做法。您可以创建其他类并将其委派给其他类。它使工作实现分叉,并保持可读性。以后,您可以用更少的劳动力更新您的代码。

Yes you are right, any class or object can be a delegate of any other, even of itself. But I would say it is not a good practice. You can create other class and delegate it to other. It bifurcates the work implementation and readability is maintained. And in future you can update your code with less labor.

这篇关于Objective-C对象可以是自己的代理吗?是好的编程实践吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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