0

我有一个应用程序,它由数组形式的许多不同的问题组成。我把这些数组放入不同的swift文件中,即:QuestionsFile1.swift,QuestionsFile 2.swift,QuestionFile3.swift,QuestionFile4.swift ....等等。根据所选的UITableViewCell打开几个swift文件之一

我有一个UITableView是示出了在表视图即Questions1,Questions2,Questions3,Questions4 ...等的每一个单元,这些各个部分。

我有它设置,以便选择UITableViewCell的时候会显示与快捷文件相关联的的viewController。然而这意味着我在storyBoard上做了很多viewController。

如何我只有一个的viewController,并与根据不同的文件迅速填充的问题是在其上的UITableViewCell选择是什么?

我选择使用

  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的各种快捷文件的问题,填充它调用UIViewControllers。因为我认为我可以拥有很多viewController。

回答

0

是的,你是对的 - 它看起来像你的问题文件表改变的是内容,所以你应该有一个的tableView的单一视图,并填充它的基础上你想要的问题。

您应该将问题存储在数据文件中,而不是将它们作为swift类进行硬编码,因此请阅读并解析应用程序包中的文本文件或许多轻量级数据库中的文本文件 - Realm或(可能矫枉过正)CoreData。

+0

谢谢:)。有什么教程或例子可以推荐? – pete800

+0

我是Ray Wenderlich教程的忠实粉丝 - 你应该在这里找到你需要的一切 - https://www.raywenderlich.com/tutorials – Russell

+0

完美的感谢之手。 – pete800

相关问题