Can an Objective-C object be its own delegate? Is

2019-05-14 01:14发布

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?

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

2条回答
Luminary・发光体
2楼-- · 2019-05-14 01:42

You can create a category to add blocks behaviour to the UIAlertView. You can check this this.

查看更多
祖国的老花朵
3楼-- · 2019-05-14 01:45

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.

查看更多
登录 后发表回答