根据所选的 UITableViewCell 打开几个 swift 个文件之一

Open one of several swift files depending on the UITableViewCell selected

我有一个应用程序,它包含许多数组形式的不同问题。我将这些数组放入不同的 swift 文件中,即 QuestionsFile1.swift、QuestionsFile 2.swift、QuestionFile3.swift、QuestionFile4.swift...等。

我有一个 UITableView,它在 table 视图的每个单元格中显示这些不同的部分,即问题 1、问题 2、问题 3、问题 4 等

我已将其设置为当 selected UITableViewCell 时,它将显示与 swift 文件关联的 viewController。然而,这意味着我在故事板上做了很多 viewController。

我如何才能只有一个 viewController 并根据 selected 的 UITableViewCell 用来自不同 swift 文件的问题填充它?

我 select 使用

调用 UIViewControllers
           override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {

        if indexPath.row == 0 || indexPath == 1 {
            self.performSegueWithIdentifier("QuestionsFile1", sender: self)
        }


        if indexPath.row == 1 {
            self.performSegueWithIdentifier("QuestionsFile2", sender: self)
        }

        if indexPath.row == 2 {
            self.performSegueWithIdentifier("QuestionsFile3", sender: self)
        }

        if indexPath.row == 3 {
            self.performSegueWithIdentifier("QuestionsFile4", sender: self)
        }

        if indexPath.row == 4 {
            self.performSegueWithIdentifier("QuestionsFile5", sender: self)
        }

        if indexPath.row == 5 {
            self.performSegueWithIdentifier("QuestionsFile6", sender: self)
        }

        if indexPath.row == 6 {
            self.performSegueWithIdentifier("QuestionsFile7", sender: self)
        }
    } 

我只想调用一个视图控制器,然后根据 UITableViewCell selected 用各种 swift 文件中的问题填充它。因为我有很多 viewController,而我认为我只能拥有一个。

是的,你是对的 - 看起来你在问题文件表中所做的只是更改内容,所以你应该有一个带有 tableView 的单一视图,并根据你想要的问题填充它。

您可能应该将问题存储在数据文件中,而不是 hard-coding 将它们存储为 swift 类,因此请查看应用程序包中的读取和解析文本文件,或其中之一许多 light-weight 数据库 - 领域或(可能矫枉过正)CoreData。