ios - ViewContainer 中 ViewController 上的条形按钮操作

标签 ios swift

我有一个容器嵌入在带有导航栏的 ViewController 中。 ContainerView 包含另一个带有一些文本字段的 ViewController。

当 ContainerView 首次显示时,文本字段被禁用。

我想做的是在导航栏中添加一个编辑按钮,以启用文本字段。

基本上, View Controller 中的条形按钮项目是否可以对容器中显示的另一个 View Controller 执行操作?

最佳答案

在这种情况下你可以做一些小技巧

条形按钮将在 ViewController 中,但我们可以将 ContainerView 的内容存储在第一个 ViewController 的变量中

为此,我建议让 ContainerView 的内容有一个自定义类,这样您就可以在其中编写一个函数

这里是一个关于如何捕获ContainerView的内容的例子

class ViewController: UIViewController{
    weak var containter: ContainerViewController!

    @IBAction func menuAction(_ sender: UIBarButtonItem) {
        //do what you want containter.doAction()
   }

    override func prepare(for segue: UIStoryboardSegue, sender: Any?){
      if let vc = segue.destination as? ContainerViewController {
         self.containter = vc
      }
   }
}

关于ios - ViewContainer 中 ViewController 上的条形按钮操作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40119588/

相关文章:

swift - 显示日期和时间

swift avfoundation AVCapturePhotoCaptureDelegate 捕获方法

ios - 导航栏中的 pageControl 未居中

ios - 如何在 swift 4 中获取 ISO8601 格式?

iphone - 添加到应用程序时 UIAlertView 崩溃

ios - 为什么我无法从网络服务获取数据,我得到反馈“列表不存在”。

iOS - 移动 View 不动画

ios - UIView addSubview 工作一次但不能工作两次

ios - 在 Swift 3 中顺时针旋转 UIImage 270 度的正确方法是什么?

swift - 函数不会等到数据下载完毕