我尝试了2种方法来将数据从ViewController传递到ContainerView,并带有和不带有segue这里没有segue方法
ViewController
类DetailPostBookReviewVC:UIViewController {
var postid: String!
@IBAction func Menubutton(_ sender: Any) {
print(postid!)
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let vc = storyboard.instantiateViewController(withIdentifier: "MenuBookReviewVC") as! MenuBookReviewVC
vc.favpostid = postid
}
ContainerView
class MenuBookReviewVC:UIViewController {
var favpostid = String()
@IBAction func Deletepost(_ sender: Any) {
print(favpostid)
}
}
结果favposid具有Nill值
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if
segue.identifier == "MyIdentifierInStorybiard",
let controller = segue.destination as? MenuBookReviewVC {// Set that
controller.favpostid = postid
}
}