ios - didselectrowat Indexpath 使用两个发送者和一个公共(public) Segue 标识符

标签 ios swift

这是我在 Xcode 中的代码...但是我得到的条件绑定(bind)的初始化程序必须具有可选类型,而不是“Wires_Cables_Details_Menu”。任何解决方案

func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath)
{
    if let  formulation_type_a_menu =
        Wires_Cables_Category_MasterData.instance.getformulations_type_a()[indexPath.row]
    {
        performSegue(withIdentifier: "WC_Formulation_Segue", sender: formulation_type_a_menu)
    }
    else
    {
        let forumulation_type_c_menu = Wires_Cables_Category_MasterData.instance.getformulations_type_c()[indexPath.row]
        performSegue(withIdentifier: "WC_Formulation_Segue", sender: forumulation_type_c_menu)
    }
}

最佳答案

if let 语句中的操作不返回可选值。它永远不会是nil,所以条件绑定(bind)不是必需的。这里有两条前进的路。您可以修改 Wires_Cables_Category_MasterData.instancegetformulations_type_a() 以返回可选类型,或者您可以找到一些其他条件来决定是否调用 getformulations_type_a() getformulations_type_c() 不涉及条件绑定(bind)。然而,现在的错误是因为您试图用 if let

解开一个实际上不是可选的“可选”

关于ios - didselectrowat Indexpath 使用两个发送者和一个公共(public) Segue 标识符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46997157/

相关文章:

java - 如何在基于 Java 的应用程序服务器上使用 GCM 向 iOS 设备发送推送通知

iOS:Firebase removeValue 似乎正在损坏数组数据?

ios - 在 Swift 中,如何遍历 UITableView 中的每个单元格然后获取其属性?

ios - 如何创建具有对角线切割的 UIImageView?

iphone - Xcode 字体大小在 iPhone 上测试时随机变化

ios - swift : How to update UILabel from another class X: UIButton

ios - 有没有办法在 swift 中向除一个节点之外的所有创建的节点添加操作?

ios - 如何从 Swift 中删除 Parse 中的对象

ios - 选项卡栏,当来自另一个选项卡的 View Controller 时弹出到 Root View Controller (默认 vc)

ios - -[UIViewController tableView :numberOfRowsInSection:]: unrecognized selector sent to instance 0x7ff437517770