dvkch
dvkch

Reputation: 1109

Connect action of a XIB loaded from a custom class to a storyboard

I'm trying to create a reusable component to display some photo collection. The basic flow is the following :

I 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 !

View from XCode

Upvotes: 2

Views: 264

Answers (1)

Protheus
Protheus

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

Related Questions