Reputation: 1109
I'm trying to create a reusable component to display some photo collection. The basic flow is the following :
View
. It contains my so called library, designed programmatically and loaded from storyboard by assigning a custom classPhotoLib
to create a new PhotoCell
from the photo pathI would like my PhotoCell
to be touch enabled so when I tap it, it opens the second view in a modal way, but from what I read I cannot do this from my PhotoCell
or the UIImageView inside (not a controller).
So how can I do ? View
is embedded in a NavigationController, even if not shown in the screenshots below.
Thank you !
Upvotes: 2
Views: 264
Reputation: 3068
If you create Photocell in photolib, then photolib should implementing delegate methods from photocell. But photolib itself is not rootviewcontroller, so it should declare delegate methods itself, and the containing view should implement it.
Basically you pass Photocell from itself to Photolib (which implements delegate method
-(void) openPhotoCell:(Photocell*)cell
{
[self.delegate openPhotocell:(Photocell*)cell];
}
, then it passes it to View, which in its turn opens it.
It may seem like pulling a tooth from an ear, but actually it's quite working and if you write good self-explanatory code, it's not a problem. I'm currently working on some big project with tens views and controllers and it works pretty good and nobody has problem with that.
If you have more layers, then maybe you should look into NSNotification.
Hope it helped, I'd be glad to explain more.
UPD:
Links:
about delegates in cocoa fundamentals guide
delegation pattern in wikipedia
Upvotes: 2