0

I've read in other posts that having multiple delegates in iOS is not the right way of doing things (and perhaps not even possible?), and instead you should be using things such as NSNotifications to alert other (multiple) View Controllers of events.

Is it better practice to keep an object's delegate the same throughout the runtime of the app, or is it useful to change the delegate to whichever VC is modal at any given time.

Here's an example: I have some simulator class that's running in the background and generating random numbers that will be used by several different view controllers in the application. Since only one VC can be viewable at a time, I could just make the active VC the delegate of the simulator, and switch the delegate every time the UI changes.

...or I can use Notifications like I am doing now, and have the VC register for notifications upon loading.

Thanks

4

1 回答 1

0

实际上,委托是代表其他对象执行某些工作的对象。您似乎遇到的情况是各种对象都是数据提供者的客户。您所描述的后台任务负责完成视图控制器只是帮助完成的事情是没有意义的。

为了使实现适合结构,我建议将背景对象分配为视图控制器的“数据提供者”属性或保留通知...取决于您喜欢的耦合程度以及您启动的类数据传输。

于 2012-12-18T15:16:13.763 回答