简体   繁体   English

从子视图控制器内部访问功能

[英]Accessing function from inside of a subview controller

I am using a walkthrough library written in swift , and I am trying to have the keyboard to be displayed only on a specific step in the walkthrough. 我正在使用以swift编写演练库 ,并且试图使键盘仅在演练的特定步骤上显示。 If I add a textField to that specific view controller in the storyboard, and make it become the first responder, the keyboard is shown for all of the other view controllers as well. 如果我将一个textField添加到情节提要中的该特定视图控制器,并使其成为第一响应者,则还将显示所有其他视图控制器的键盘。 What I am trying to accomplish is when the user is on this specific page, I would like the keyboard to be present, and when they scroll away, for it to disappear with the swipe. 我要完成的工作是,当用户位于该特定页面上时,我希望键盘存在,并且当他们滚动离开时,随着滑动而消失。

The library offers a function called walkthroughPageDidChange , however it's on the master view controller where all the subview controllers are attached to. 该库提供了一个名为walkthroughPageDidChange的函数,但是该函数位于主视图控制器上,所有子视图控制器均已连接到该视图上。 I can check if the pageNumber is the one I want it to be, however I am not sure how to accomplish accessing a function inside of one of the attached view controller pages. 我可以检查pageNumber是否是我想要的那个,但是我不确定如何完成对附加的视图控制器页面之一内部函数的访问。

I would like to access the keyboard controller with the following functions: 我想使用以下功能访问键盘控制器:

KeyboardViewController.showKeyboard() - becomeFirstResponser for textField keyboardViewController.hideKeyboard() - resignFirstResponder for textField KeyboardViewController.showKeyboard() -成为textField的FirstResponser keyboardViewController.hideKeyboard() -resignFirstResponder for textField

if pageNumber == 2 {
  KeyboardViewController.showKeyboard()
}else{
  KeyboardViewController.hideKeyboard()
}

How would I accomplish this? 我将如何完成? How would I be able to access this function inside of another view controller? 我如何能够在另一个视图控制器内部访问此功能?

Thank you in advance. 先感谢您。

You should keep an array of your ViewControllers in the parent ViewController when you create them. 创建它们时,应在父ViewController中保留一个ViewControllers数组。 So in your array you pick the right controller and call the function you want. 因此,在您的阵列中,选择合适的控制器并调用所需的函数。 I did not see the code where the viewcontrollers are stored in an array your link, but you can just add it where you create the VCs. 我没有看到在链接数组中存储视图控制器的代码,但是可以将其添加到创建VC的位置。

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

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