morcutt
morcutt

Reputation: 3749

How should this be implemented? Delegation

I have many views that I want to communicate with one other view. We'll call that one other view "main view". What I want to do is have the "many other views" be able to send a method to "main view" that adds a subview. Would I create a delegate method? If so, would I create the delegate in the "main view" and then have to set it in the "many other views". I am just wrapping my mind around how delegates work.

Upvotes: 0

Views: 98

Answers (1)

kperryua
kperryua

Reputation: 10534

The term 'delegate' is usually used only when an object is sufficiently general and will be reused in many situations with many possible different delegates. For example, a table view, a very generic object, has a delegate that customizes its behavior, but a custom view of your own making that is used for your own purposes might not.

It sounds like you have a very simply many-to-one relationship between your "other" views and your "main" view. You can probably simply make a property on your "other" views (e.g. mainView), or make some other method which allows your "other" views easy access to the "main" view pointer, and send your message to it.

Upvotes: 1

Related Questions