我想通过使用github扩展(https://github.com/Orderella/PopupDialog)将信息传递给我的自定义PopUpViewController。 Popup使用一个名为PopUpViewController(带有xib文件)的视图控制器,并且PopUp从其启动的视图控制器称为MainViewController。Swift:如何将信息传递到弹出视图?
传递给PopUpViewController的信息将是一个String类型的数组(名为:popUpArray),用于在一个表(名为tableView)中显示包含的信息。
MainViewController代码:
func showCustomDialog(_ sender: UIButton) {
// Create a custom view controller
let PopUpVC = PopUpViewController(nibName: "PopUpViewController", bundle: nil)
// Create the dialog
let popup = PopupDialog(viewController: PopUpVC, buttonAlignment: .horizontal, transitionStyle: .bounceDown, gestureDismissal: true)
// Create second button
let buttonOne = DefaultButton(title: "Ok", dismissOnTap: true) {
}
// Add buttons to dialog
popup.addButton(buttonOne)
// Present dialog
present(popup, animated: true, completion: nil)
}
PopUpViewController代码:
import UIKit
class PopUpViewController: UIViewController {
@IBOutlet weak var imageView: UIImageView!
@IBOutlet weak var titleLabel: UILabel!
@IBOutlet weak var tableView: UITableView!
您必须使用协议委托来传递信息。 –