gpt4 book ai didi

ios - 谁的 View 不在窗口层次结构中? swift

转载 作者:行者123 更新时间:2023-11-28 07:04:48 25 4
gpt4 key购买 nike

我想要显示一个 TableView Controller 。因此,我在下面的 completionwithitemshandler 属性中显示了 View Controller 。

 let activityViewController = UIActivityViewController(activityItems:[memeedimage] , applicationActivities: nil)
presentViewController(activityViewController, animated: true, completion: nil)

activityViewController.completionWithItemsHandler = {
(activity, success, returneditems, error) in
println("Activity: \(activity) Success: \(success) Items: \(returneditems) Error: \(error)")
self.save()
activityViewController.dismissViewControllerAnimated(true, completion: nil)

let memevc:MemeTableViewController = MemeTableViewController()
activityViewController.presentViewController(memevc, animated: true, completion: nil)
}

但我收到以下运行时错误:

Warning: Attempt to present <MemeMe.MemeTableViewController: 0x7fc4b6179600> on <UIActivityViewController: 0x7fc4b6148180> whose view is not in the window hierarchy!

所以我认为这与我解包具有可选数据类型的 meme 对象有关。

 func save(){
var meme : MemeObject?
if let memez = meme{
meme = MemeObject(textFieldtop : texfieldtop.text! ,textFieldbottom : textfieldbottom.text! ,image : imagePickerView.image! , memedImage : generateMemedImage())
(UIApplication.sharedApplication().delegate as! AppDelegate).memes.append(meme!)
}
else{
println("Optionals man")
}


}

最佳答案

问题是您正在关闭 UIActivityViewController,然后尝试从中呈现另一个 View Controller 。相反,你想要的是从你展示事件 View Controller 的同一个 View Controller 展示你的新 View Controller 。

例如,您可以在 Activity View Controller dismiss 完成后呈现新的 View Controller:

let activityViewController = UIActivityViewController(activityItems:[memeedimage] , applicationActivities: nil)
presentViewController(activityViewController, animated: true, completion: nil)


activityViewController.completionWithItemsHandler = {
(activity, success, returneditems, error) in
println("Activity: \(activity) Success: \(success) Items: \(returneditems) Error: \(error)")
self.save()
activityViewController.dismissViewControllerAnimated(true, completion: {
let memevc:MemeTableViewController = MemeTableViewController()
self.presentViewController(memevc, animated: true, completion: nil)
})

注意:在您最初的“presentViewController”中,您不需要使用 self.presentViewController(),但是因为新调用是在一个使用 self.presentViewController() 的 block 内,所以它明确表明应该由 self 呈现它。

关于ios - 谁的 View 不在窗口层次结构中? swift ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30966090/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com