Swift:我想导航到几个viewcontroller

时间:2017-06-17 03:54:19

标签: swift

我想在单击表格行时转到多个视图控制器。 所以我制作了如下代码。

func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) 
{

        var targetId = ""
        var targetController: UITableViewController!

        switch indexPath.row {
        case 2:
            targetId = "TableView1"
            targetController = TableViewController1()
        case 2:
            targetId = "TableView2"
            targetController = TableViewController2()
        case 2:
            targetId = "TableView3"
            targetController = TableViewController3()
        default:
            return
        }

        let detailView = self.storyboard?.instantiateViewController(withIdentifier: targetId) as! targetController
        self.navigationController?.pushViewController(detailView, animated: true)

}

但我可以看到错误消息“使用未声明的类型'targetController'”。 如何导航到多个视图控制器?

1 个答案:

答案 0 :(得分:0)

您无法将对象强制转换为变量(实例)。

但是,如果所有控制器都是+-----------------+-------------------------------------------------+-----------------------------+-------------------------------------------------+-----------------------------------------------+ | s | p1 | o1 | p2 | o2 | +-----------------+-------------------------------------------------+-----------------------------+-------------------------------------------------+-----------------------------------------------+ | ex:Djamel | ex:hasFirstName | ex:DjamelFirstName | ex:hasPurpose | ex:current | | ex:Djamel | ex:hasFirstName | ex:DjamelFirstName | ex:hasRecipient | ex:ours | | ex:Djamel | ex:hasFirstName | ex:DjamelFirstName | ex:hasRetention | ex:no-retention | | ex:Djamel | ex:hasFirstName | ex:DjamelFirstName | ex:hasValue | Nom | | ex:Djamel | ex:hasFirstName | ex:DjamelFirstName | http://www.w3.org/1999/02/22-rdf-syntax-ns#type | ex:FirstName | | ex:Djamel | ex:hasIdentityCard | ex:DjamelIdentityCard | ex:hasDeliveryDate | ex:DjamelIdentityCardDeliveryDate | | ex:Djamel | ex:hasIdentityCard | ex:DjamelIdentityCard | ex:hasExpirationDate | ex:DjamelIdentityCardExpirationDate | | ex:Djamel | ex:hasIdentityCard | ex:DjamelIdentityCard | ex:hasNumber | ex:DjamelIdentityCardNumber | | ex:Djamel | ex:hasIdentityCard | ex:DjamelIdentityCard | http://www.w3.org/1999/02/22-rdf-syntax-ns#type | ex:IdentityCard | | ex:Djamel | http://www.w3.org/1999/02/22-rdf-syntax-ns#type | ex:Client | http://www.w3.org/1999/02/22-rdf-syntax-ns#type | http://www.w3.org/2000/01/rdf-schema#Class | | ex:Djamel | http://www.w3.org/1999/02/22-rdf-syntax-ns#type | ex:Client | http://www.w3.org/1999/02/22-rdf-syntax-ns#type | http://www.w3.org/2000/01/rdf-schema#Resource | | ex:Djamel | ex:hasAdress | ex:DjamelAdress | ex:hasPurpose | ex:current | | ex:Djamel | ex:hasAdress | ex:DjamelAdress | ex:hasRecipient | ex:ours | | ex:Djamel | ex:hasAdress | ex:DjamelAdress | ex:hasRetention | ex:no-retention | | ex:Djamel | ex:hasAdress | ex:DjamelAdress | ex:hasValue | Mon Adresse | | ex:Djamel | ex:hasAdress | ex:DjamelAdress | http://www.w3.org/1999/02/22-rdf-syntax-ns#type | ex:Adress | | ex:Djamel | ex:hasBdDate | ex:DjamelBdDate | ex:hasPurpose | ex:current | | ex:Djamel | ex:hasBdDate | ex:DjamelBdDate | ex:hasRecipient | ex:ours | | ex:Djamel | ex:hasBdDate | ex:DjamelBdDate | ex:hasRetention | ex:no-retention | | ex:Djamel | ex:hasBdDate | ex:DjamelBdDate | ex:hasValue | 19/06/1991 | | ex:Djamel | ex:hasBdDate | ex:DjamelBdDate | http://www.w3.org/1999/02/22-rdf-syntax-ns#type | ex:BdDate | | ex:Djamel | ex:hasCreditCard | ex:DjamelCreditCard | ex:hasCCType | ex:DjamelCCType | | ex:Djamel | ex:hasCreditCard | ex:DjamelCreditCard | ex:hasNumber | ex:DjamelCreditCardNumber | | ex:Djamel | ex:hasCreditCard | ex:DjamelCreditCard | http://www.w3.org/1999/02/22-rdf-syntax-ns#type | ex:CreditCard | | ex:Djamel | ex:hasPassPort | ex:DjamelPassPort | ex:hasDeliveryDate | ex:DjamelPassPortDeliveryDate | | ex:Djamel | ex:hasPassPort | ex:DjamelPassPort | ex:hasExpirationDate | ex:DjamelPassPortExpirationDate | | ex:Djamel | ex:hasPassPort | ex:DjamelPassPort | ex:hasNumber | ex:DjamelPassPortNumber | | ex:Djamel | ex:hasPassPort | ex:DjamelPassPort | http://www.w3.org/1999/02/22-rdf-syntax-ns#type | ex:PassPort | | ex:Djamel | ex:hasDriverLicense | ex:DjamelDriverLicense | ex:hasDeliveryDate | ex:DjamelDriverLicenseDeliveryDate | | ex:Djamel | ex:hasDriverLicense | ex:DjamelDriverLicense | ex:hasExpirationDate | ex:DjamelDriverLicenseExpirationDate | | ex:Djamel | ex:hasDriverLicense | ex:DjamelDriverLicense | ex:hasNumber | ex:DjamelDriverLicenseNumber | | ex:Djamel | ex:hasDriverLicense | ex:DjamelDriverLicense | http://www.w3.org/1999/02/22-rdf-syntax-ns#type | ex:DriverLicense | | ex:Djamel | ex:hasLastName | ex:DjamelLastName | ex:hasPurpose | ex:current | | ex:Djamel | ex:hasLastName | ex:DjamelLastName | ex:hasRecipient | ex:ours | | ex:Djamel | ex:hasLastName | ex:DjamelLastName | ex:hasRetention | ex:no-retention | | ex:Djamel | ex:hasLastName | ex:DjamelLastName | ex:hasValue | Prenom | | ex:Djamel | ex:hasLastName | ex:DjamelLastName | http://www.w3.org/1999/02/22-rdf-syntax-ns#type | ex:LastName | | ex:Djamel | ex:hasService | ex:RentVehicle | NA | NA | | ex:Djamel | ex:hasAge | ex:DjamelAge | ex:hasPurpose | ex:current | | ex:Djamel | ex:hasAge | ex:DjamelAge | ex:hasRecipient | ex:ours | | ex:Djamel | ex:hasAge | ex:DjamelAge | ex:hasRetention | ex:no-retention | | ex:Djamel | ex:hasAge | ex:DjamelAge | ex:hasValue | 25 | | ex:Djamel | ex:hasAge | ex:DjamelAge | http://www.w3.org/1999/02/22-rdf-syntax-ns#type | ex:Age | | ex:ergergghbjk_ | ex:hasAdress | ex:ergergghbjk_Adress | ex:hasPurpose | ex:current | | ex:ergergghbjk_ | ex:hasAdress | ex:ergergghbjk_Adress | ex:hasRecipient | ex:ours | | ex:ergergghbjk_ | ex:hasAdress | ex:ergergghbjk_Adress | ex:hasRetention | ex:no-retention | | ex:ergergghbjk_ | ex:hasAdress | ex:ergergghbjk_Adress | ex:hasValue | ergdrg | | ex:ergergghbjk_ | ex:hasAdress | ex:ergergghbjk_Adress | http://www.w3.org/1999/02/22-rdf-syntax-ns#type | ex:Adress | | ex:ergergghbjk_ | ex:hasAge | ex:ergergghbjk_Age | ex:hasPurpose | ex:current | | ex:ergergghbjk_ | ex:hasAge | ex:ergergghbjk_Age | ex:hasRecipient | ex:ours | | ex:ergergghbjk_ | ex:hasAge | ex:ergergghbjk_Age | ex:hasRetention | ex:no-retention | | ex:ergergghbjk_ | ex:hasAge | ex:ergergghbjk_Age | ex:hasValue | 4 | | ex:ergergghbjk_ | ex:hasAge | ex:ergergghbjk_Age | http://www.w3.org/1999/02/22-rdf-syntax-ns#type | ex:Age | | ex:ergergghbjk_ | ex:hasBdDate | ex:ergergghbjk_BdDate | ex:hasPurpose | ex:current | | ex:ergergghbjk_ | ex:hasBdDate | ex:ergergghbjk_BdDate | ex:hasRecipient | ex:ours | | ex:ergergghbjk_ | ex:hasBdDate | ex:ergergghbjk_BdDate | ex:hasRetention | ex:no-retention | | ex:ergergghbjk_ | ex:hasBdDate | ex:ergergghbjk_BdDate | ex:hasValue | 31/12/2011 | | ex:ergergghbjk_ | ex:hasBdDate | ex:ergergghbjk_BdDate | http://www.w3.org/1999/02/22-rdf-syntax-ns#type | ex:BdDate | | ex:ergergghbjk_ | ex:hasIdentityCard | ex:ergergghbjk_IdentityCard | ex:hasDeliveryDate | ex:ergergghbjk_IdentityCardDeliveryDate | | ex:ergergghbjk_ | ex:hasIdentityCard | ex:ergergghbjk_IdentityCard | ex:hasExpirationDate | ex:ergergghbjk_IdentityCardExpirationDate | | ex:ergergghbjk_ | ex:hasIdentityCard | ex:ergergghbjk_IdentityCard | ex:hasNumber | ex:ergergghbjk_IdentityCardNumber | | ex:ergergghbjk_ | ex:hasIdentityCard | ex:ergergghbjk_IdentityCard | http://www.w3.org/1999/02/22-rdf-syntax-ns#type | ex:IdentityCard | | ex:ergergghbjk_ | ex:hasPassPort | ex:ergergghbjk_PassPort | ex:hasDeliveryDate | ex:ergergghbjk_PassPortDeliveryDate | | ex:ergergghbjk_ | ex:hasPassPort | ex:ergergghbjk_PassPort | ex:hasExpirationDate | ex:ergergghbjk_PassPortExpirationDate | | ex:ergergghbjk_ | ex:hasPassPort | ex:ergergghbjk_PassPort | ex:hasNumber | ex:ergergghbjk_PassPortNumber | | ex:ergergghbjk_ | ex:hasPassPort | ex:ergergghbjk_PassPort | http://www.w3.org/1999/02/22-rdf-syntax-ns#type | ex:PassPort | | ex:ergergghbjk_ | ex:hasService | ex:BuyBusTicket | http://www.w3.org/1999/02/22-rdf-syntax-ns#type | http://www.w3.org/2002/07/owl#NamedIndividual | | ex:ergergghbjk_ | ex:hasService | ex:BuyBusTicket | http://www.w3.org/1999/02/22-rdf-syntax-ns#type | ex:LandTransportationService | | ex:ergergghbjk_ | http://www.w3.org/1999/02/22-rdf-syntax-ns#type | ex:Client | http://www.w3.org/1999/02/22-rdf-syntax-ns#type | http://www.w3.org/2000/01/rdf-schema#Class | | ex:ergergghbjk_ | http://www.w3.org/1999/02/22-rdf-syntax-ns#type | ex:Client | http://www.w3.org/1999/02/22-rdf-syntax-ns#type | http://www.w3.org/2000/01/rdf-schema#Resource | | ex:Taleb | ex:hasAdress | ex:TalebAdress | ex:hasPurpose | ex:current | | ex:Taleb | ex:hasAdress | ex:TalebAdress | ex:hasRecipient | ex:ours | | ex:Taleb | ex:hasAdress | ex:TalebAdress | ex:hasRetention | ex:no-retention | | ex:Taleb | ex:hasAdress | ex:TalebAdress | ex:hasValue | binjk,l | | ex:Taleb | ex:hasAdress | ex:TalebAdress | http://www.w3.org/1999/02/22-rdf-syntax-ns#type | ex:Adress | | ex:Taleb | ex:hasAge | ex:TalebAge | ex:hasPurpose | ex:current | | ex:Taleb | ex:hasAge | ex:TalebAge | ex:hasRecipient | ex:ours | | ex:Taleb | ex:hasAge | ex:TalebAge | ex:hasRetention | ex:no-retention | | ex:Taleb | ex:hasAge | ex:TalebAge | ex:hasValue | 2 | | ex:Taleb | ex:hasAge | ex:TalebAge | http://www.w3.org/1999/02/22-rdf-syntax-ns#type | ex:Age | | ex:Taleb | ex:hasBdDate | ex:TalebBdDate | ex:hasPurpose | ex:current | | ex:Taleb | ex:hasBdDate | ex:TalebBdDate | ex:hasRecipient | ex:ours | | ex:Taleb | ex:hasBdDate | ex:TalebBdDate | ex:hasRetention | ex:no-retention | | ex:Taleb | ex:hasBdDate | ex:TalebBdDate | ex:hasValue | 20/12/2013 | | ex:Taleb | ex:hasBdDate | ex:TalebBdDate | http://www.w3.org/1999/02/22-rdf-syntax-ns#type | ex:BdDate | | ex:Taleb | ex:hasIdentityCard | ex:TalebIdentityCard | ex:hasDeliveryDate | ex:TalebIdentityCardDeliveryDate | | ex:Taleb | ex:hasIdentityCard | ex:TalebIdentityCard | ex:hasExpirationDate | ex:TalebIdentityCardExpirationDate | | ex:Taleb | ex:hasIdentityCard | ex:TalebIdentityCard | ex:hasNumber | ex:TalebIdentityCardNumber | | ex:Taleb | ex:hasIdentityCard | ex:TalebIdentityCard | http://www.w3.org/1999/02/22-rdf-syntax-ns#type | ex:IdentityCard | | ex:Taleb | ex:hasPassPort | ex:TalebPassPort | ex:hasDeliveryDate | ex:TalebPassPortDeliveryDate | | ex:Taleb | ex:hasPassPort | ex:TalebPassPort | ex:hasExpirationDate | ex:TalebPassPortExpirationDate | | ex:Taleb | ex:hasPassPort | ex:TalebPassPort | ex:hasNumber | ex:TalebPassPortNumber | | ex:Taleb | ex:hasPassPort | ex:TalebPassPort | http://www.w3.org/1999/02/22-rdf-syntax-ns#type | ex:PassPort | | ex:Taleb | http://www.w3.org/1999/02/22-rdf-syntax-ns#type | ex:Client | http://www.w3.org/1999/02/22-rdf-syntax-ns#type | http://www.w3.org/2000/01/rdf-schema#Class | | ex:Taleb | http://www.w3.org/1999/02/22-rdf-syntax-ns#type | ex:Client | http://www.w3.org/1999/02/22-rdf-syntax-ns#type | http://www.w3.org/2000/01/rdf-schema#Resource | +-----------------+-------------------------------------------------+-----------------------------+-------------------------------------------------+-----------------------------------------------+ 的子类,则根本不需要任何类型转换

UIViewController