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

标签 ios swift swift4 nsdictionary

在过去的 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/

相关文章:

ios - 无法使用 AutoLayout 设置 UICollectionViewCell 内容的宽度

ios - 使用 xcodebuild 偶尔会看到构建错误

javascript - 在 iPhone Safari 中使用 ScriptProcessorNode

swift - 不请求访问 coreLocation 的权限并 swift 崩溃

Swift 4 Firebase 实时数据库嵌套字典

ios - XLPagerTabStrip 标签没有获得相等的屏幕宽度 :Swift

objective-c - 为 iOS 设备创建 wordpress 网站阅读器 i :e showing notification/Reading content only if the site content/feed is updated

ios - Swift vs Objective-C 斐波那契数列速度比较

ios - 如何通过自动布局以编程方式添加 InputAccessoryView?

ios - UITableView在屏幕上点击之前不可见