简体   繁体   English

在故事板和UITabbarController中基于视图的委派

[英]View based delegation in storyboards and UITabbarController

I know this has been asked, but I can't figure out how to make this work with my app -- I'm sure I'm doing it wrong. 我知道有人问过这个问题,但是我不知道该如何使用我的应用程序进行这项工作-我确定我做错了。

I have two view controllers embedded inside a UITabBarViewContoller , FirstViewController and SecondViewController . 我在UITabBarViewContoller嵌入了两个视图控制器, FirstViewControllerSecondViewController SecondViewController is nothing more then a few UITextFields for managing a hostname and port that the app connects to. SecondViewController就是一些用于管理应用程序连接到的主机名和端口的UITextFields

FirstViewController contains most of the code (which I know isn't very MVC oriented). FirstViewController包含大多数代码(我知道它不是非常面向MVC的)。 I'm trying to implement Delegation from SecondViewController back to FirstViewController ( Passing Data between View Controllers ) but it seems like my delegate methods aren't being called. 我试图实现从SecondViewControllerFirstViewController在View Controllers之间传递数据 ),但似乎未调用我的委托方法。 Since this is based on storyboards, I'm not creating the instance of SecondViewController and I'm not sure how to set the Delegate. 由于这是基于情节SecondViewController ,因此我没有创建SecondViewController的实例,也不确定如何设置Delegate。 Is there a way to access the instance of SecondViewController so I can set the Delegate? 有没有一种方法可以访问SecondViewController的实例,以便我可以设置Delegate?

milesper thank you! 哩程谢谢!

My solution (in swift) 我的解决方案(迅速)

    let secondView = self.tabBarController.viewControllers[1] as SecondViewController
    secondView.delegate = self

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM