Assigning a view controller to be the delegate of a subview which is not directly descendent?
Posted
by ambertch
on Stack Overflow
See other posts from Stack Overflow
or by ambertch
Published on 2010-05-10T05:15:01Z
Indexed on
2010/05/10
5:18 UTC
Read the original article
Hit count: 274
iphone
|objective-c
I am writing an iphone app where in numerous cases a subview needs to talk to its superview. For example:
- View A has a table view that contains photos
- A has a subview B which allows users to add photos, upon which I want to auto append them to A's table view
So far I have been creating a @protocol in B, and registering A as the delegate.
The problem in my case is that B has a subview C that allows users to add content, and I want actions in C to invoke changes in its grandparent, A.
Currently I am working around this by passing around a self pointer to my base view controller (C.delegate = B.delegate), but it doesn't seem very proper to me. Any thoughts? (and/or general advice on code organization when all sort of subviews needs to talk to superviews would be greatly appreciated)
Thanks!
© Stack Overflow or respective owner