简体   繁体   English

swift 5中如何从viewcontroller发送数据到embedded viewcontroller?

[英]How to send data from viewcontroller to embded viewcontroller in swift 5?

I have one viewcontroller where i am using container view and embedding another viewcontroller in that (using storyboard).我有一个视图控制器,我在其中使用容器视图并在其中嵌入另一个视图控制器(使用情节提要)。 I am trying pass data from viewcontroller to embedded viewcontroller using prepersegue but not able to do that.我正在尝试使用 prepersegue 将数据从 viewcontroller 传递到嵌入式 viewcontroller 但无法做到这一点。

is there any better way to pass data from viewcontroller to embedded viewcontroller.有没有更好的方法将数据从 viewcontroller 传递到嵌入式 viewcontroller。

import UIKit

class ViewMyDiary: UIViewController {

    var alerts = [blogDataModel]() //getting value here from another viewcontroller 


    override func viewDidLoad() {
        super.viewDidLoad()
    }

    override func viewWillAppear(_ animated: Bool) {
         self.performSegue(withIdentifier: "calenderSegue", sender: self);

    }

     func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {

        if (segue.identifier == "calenderSegue")
        {
            let vc: CalenderViewController = segue.destination as! CalenderViewController
            vc.alerts = alerts
        }
    }
}

for this i am getting error like "There are unexpected subviews in the container view. Perhaps the embed segue has already fired once or a subview was added programmatically?"为此,我收到类似“容器视图中存在意外子视图。也许嵌入转场已经触发一次或以编程方式添加了子视图?”的错误。

在此处输入图像描述

Thank you for help谢谢你的帮助

You don't need to do this for embed segue..embed segue fired automatically once or a subview was added programmatically您不需要为嵌入 segue 执行此操作。嵌入 segue 自动触发一次或以编程方式添加子视图

override func viewWillAppear(_ animated: Bool) {
         self.performSegue(withIdentifier: "calenderSegue", sender: self);

    }

override func prepare(for segue: UIStoryboardSegue, sender: Any?) {

     if let vc: CalenderViewController = segue.destination as? CalenderViewController {
          vc.alerts = alerts
      }

 }

remove this code and you are good to go删除此代码,您就可以使用 go

暂无
暂无

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

相关问题 如何使用Swift 3将数据从ViewController A传递到另一个ViewController B - How to pass data from viewcontroller A to another viewcontroller B using swift 3 如何将数据从模态呈现的 ViewController 传递到 swift 5 中的父 ViewController? - How to pass the data from modally presented ViewController to parent ViewController in swift 5? 如何将数据从 Swift ViewController 传递到 Obj-C ViewController? - How to pass data from a Swift ViewController to an Obj-C ViewController? 如何从ViewController访问Swift 3中的另一个viewController - How to access from viewController another viewController in Swift 3 如何在Swift3中将collectionView数据发送到另一个ViewController? - How to send collectionView data to another ViewController in swift3? 从Swift ViewController向目标c ViewController发送消息 - Send message from swift ViewController to objective c ViewController 如何将信息从一个视图控制器发送到另一个? (斯威夫特 - IOS) - How to send info from one viewcontroller to another? (Swift - IOS) 将进度从NSURLSession发送到ViewController [swift-iOS] - Send Progress from NSURLSession to ViewController [swift - iOS] Swift:将数据从ViewController中的tableView传递到另一个ViewController - Swift: Passing data from a tableView in a ViewController to another ViewController Swift 4-将数据从ViewController传递到ViewController到标签栏 - Swift 4 - pass data from ViewController to a ViewController to a tab bar
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM