【发布时间】:2020-05-21 02:31:07
【问题描述】:
我创建了 .xib 文件并将它们与适当的视图控制器连接起来。不幸的是,它并不顺利。
我已经检查并尝试了很多示例,但不适用于最新版本。使用 Xcode 11.3 和 iOS 13。
这是我尝试过的代码。
TopView.swift
@IBAction func btnConnectTapped(_ sender: Any) {
print("tapped")
var listVC: PopupView // This one is UIView and popped the window
listVC = Bundle.main.loadNibNamed("PopupView", owner: self, options: nil)?.first as! PopupView
self.view.addSubview(listVC)
// Tried for the UIViewController and not worked
/*let VC = ScanViewController(nibName: "ScanViewController", bundle: nil)
//self.present(VC, animated: true, completion: nil)
self.navigationController?.pushViewController(VC, animated: true)*/
}
Popup.swift // 关闭弹出的视图
@IBAction func btnCancelTapped(_ sender: Any) {
DispatchQueue.main.async {
self.removeFromSuperview()
}
}
ScanViewController 和 Popup 视图具有相同的用途。
谁能帮帮我
【问题讨论】:
-
您有什么具体问题?您没有为弹出视图设置任何约束。
-
@Sulthan 当我点击按钮删除弹出视图时,它给出了运行时错误。
-
您可以使用 PopupDialog pod 来显示弹出窗口
-
@SiddhantNigam 你能举个例子吗?
-
在xib中
btnCancelTapped是如何连接的?它是连接到视图本身还是连接到所有者?
标签: ios swift swift5 addsubview