gpt4 book ai didi

ios - 在 ViewController 之间使用 instantiateViewControllerWithIdentifier 传递数据

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

在过去的 2 天里,我一直在研究这个问题并尝试各种选择,但被难住了。我有一个页面,用户可以在其中滑动单元格并看到以下选项 enter image description here

当用户点击“举报用户”时,他们应该会被带到一个页面,其中包含一个允许他们提交对其他用户的投诉的表单。第一个 VC 称为消息,它应该传递报告用户和被报告用户的用户名。现在只有报告用户被传递,因为它在 NSDictionary 中。我尝试过的最新方法是导致应用程序崩溃并出现“libc++abi.dylib:以 NSException 类型的未捕获异常终止”这是代码示例:

 let shareAction = UITableViewRowAction(style: UITableViewRowActionStyle.default, title: "Report User" , handler: { (action:UITableViewRowAction!, indexPath:IndexPath!) -> Void in


let shareMenu = UIAlertController(title: nil, message: "Report User", preferredStyle: .actionSheet)

let editBtn = UIAlertAction(title: "Harrassment, Inappropriate Content, Abuse", style: .default) { (action:UIAlertAction) in
self.reportPost(indexPath)

}
//let harrassAction = UIAlertAction(title: "Harrassment", style: UIAlertActionStyle.default, handler: nil)
let cancelAction = UIAlertAction(title: "Cancel", style: UIAlertActionStyle.cancel, handler: nil)

shareMenu.addAction(editBtn)

shareMenu.addAction(cancelAction)
self.present(shareMenu, animated: true, completion: nil)

})

func reportPost(_ indexPath : IndexPath) {
let guest = self.guest[indexPath.row]
let storyboard = UIStoryboard(name: "ReportVC", bundle: nil)
let vc = storyboard.instantiateViewController(withIdentifier: "ReportView") as! ReportViewController
vc.reportLbl.text = guest as? String
}

非常感谢任何帮助。

最佳答案

在您的 ReportVC Storyboard 中( Storyboard 的名字很奇怪,但没问题..),选择您的 ReportView 场景(在 InterfaceBuilder 中)并在 Identity Inspector 中验证其 Storyboard ID 是否设置为“ReportView”。还要确保将类设置为 ReportViewController。

它应该是这样的:

enter image description here

更新:

和techgirl聊天后,发现 Storyboard根本就没有命名为“ReportVC”。因此,对于那些阅读此答案的人,还请检查您引用的 Storyboard文件是否正确。

关于ios - 在 ViewController 之间使用 instantiateViewControllerWithIdentifier 传递数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53136941/

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