Luke
Luke

Reputation: 11476

UIView needs to push a UIViewController (delegation)

I'm having a hard time getting my head around custom delegation - I would be most grateful if someone could help me:

I have a UIViewController with a tab bar controller, and each of these contains a subclassed UIView. In one of the views, I have a UIButton in which I want to load a UIDocumentInteractionController. I already have the code to do this second part, as the document controller needs access to a UIViewController in order to get pushed to the stack.

But how can my UIView get access to the UIViewController?

I've read a plethora of things on SO tonight, such as:

I can happily hit my -(void)buttonPressed: (id)sender method, but where should it go from here to implement delegation? Should it just fire something like [delegate documentRequested: sender] assuming this method exists in my view controller?

Thanks in advance for any assistance.

Upvotes: 1

Views: 1744

Answers (1)

Sid
Sid

Reputation: 9536

I recently posted a detailed answer on how to use custom delegation. You can check it out here: dismissModalViewController AND pass data back

What you want to do here is implement the protocol in your UIView and set the UIViewController to be it's delegate.

To help you understand the linked answer better, in the answer, secondviewcontroller is equivalent to your UIView and firstviewcontroller is equivalent to your UIViewController.

Upvotes: 2

Related Questions