didselectrowat Indexpath使用两个发送者和一个公共segue标识符

时间:2017-10-29 05:35:33

标签: ios swift

这是Xcode中的我的代码...但我得到条件绑定的初始化程序必须具有可选类型,而不是' 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)
    }
}

1 个答案:

答案 0 :(得分:0)

if let语句中的操作不会返回Optional。它永远不会是nil所以不需要条件绑定。你有两条前进的道路。您可以修改Wires_Cables_Category_MasterData.instancegetformulations_type_a()以返回可选类型,也可以找到一些其他条件来决定是否调用不涉及的getformulations_type_a()getformulations_type_c()条件绑定。但是,现在的错误是因为你试图打开一个“{可选”,这个“可选”实际上不是if let

的可选项