我想在Tableview单元格ViewController中显示一个弹出窗口。我想要这个,因为在TableViewCell中是一个按钮,按下该按钮时需要弹出。请帮我!如果运行此命令,则会出现错误:
InstagramClone.SignInViewController:0x102e22b30的视图不是
在窗口层次中!
@objc func kik (){
if let Kik = user?.KikUsername {
// Prepare the popup assets
let title = "Kik Username"
let message = "The Kik username from \(user?.username) is: \(Kik)."
let image = UIImage(named: "kik-icon.jpg")
// Create the dialog
let popup = PopupDialog(title: title, message: message, image: image)
// Create buttons
let buttonOne = CancelButton(title: "Cancel") {
print("You canceled")
}
// This button will not the dismiss the dialog
let buttonTwo = DefaultButton(title: "Copy Kik Username to clipboard!", dismissOnTap: false) {
UIPasteboard.general.string = Kik
}
popup.addButtons([buttonOne, buttonTwo])
// Present dialog
self.window?.rootViewController?.present(popup, animated: true, completion: nil)
}
}
最佳答案
我认为您只需要将弹出窗口添加到主视图中:
self.view.addSubview(popup)