UIView需要推一个UIViewController(委托) [英] UIView needs to push a UIViewController (delegation)

查看:127
本文介绍了UIView需要推一个UIViewController(委托)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我很难让自己的团队围绕自己的代表团 - 如果有人可以帮助我,我将非常感激:



我有一个UIViewController,带有一个tab bar控制器,并且每个都包含一个子类UIView。在其中一个视图中,我有一个UIButton,其中我要加载一个UIDocumentInteractionController。我已经有代码做这个第二部分,因为文档控制器需要访问一个UIViewController才能被推到堆栈。



但是我的UIView如何得到访问UIViewController?



我今天晚上读了很多东西,比如:




  • 不能完成

  • 将UIViewController设置为UIView的属性,以便知道它属于哪个

  • 在UIViewController上调用nextResponder

  • 代理



我可以高兴地打我的 - (void)buttonPressed:(id)sender 方法,但是从哪里去执行委托?假设这个方法存在于我的视图控制器中,那么它应该像 [delegate documentRequested:sender] 那样被点燃?



谢谢提前获得任何帮助。

解决方案

我最近发布了一个关于如何使用自定义委托的详细答案。您可以在这里查看: dismissModalViewController并将数据传回



你想在这里做什么是在UIView中实现协议,并将UIViewController设置为委托。



为了帮助您更好地了解链接的答案,在答案中,secondviewcontroller相当于您的UIView和firstviewcontroller等效于您的UIViewController。


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:

  • It can't be done
  • Set the UIViewController as a property of the UIView so it knows which it belongs to
  • Calling nextResponder on the UIViewController
  • Delegation

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.

解决方案

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.

这篇关于UIView需要推一个UIViewController(委托)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆