根据所选的 UITableViewCell 打开几个 swift 文件之一
Posted
技术标签:
【中文标题】根据所选的 UITableViewCell 打开几个 swift 文件之一【英文标题】:Open one of several swift files depending on the UITableViewCell selected 【发布时间】:2017-01-19 18:32:19 【问题描述】:我有一个应用程序,其中包含许多以数组形式存在的不同问题。我将这些数组放入不同的 swift 文件中,即 QuestionsFile1.swift、QuestionsFile 2.swift、QuestionFile3.swift、QuestionFile4.swift....等。
我有一个 UITableView,它在表格视图的每个单元格中显示这些不同的部分,即 Questions1、Questions2、Questions3、Questions4...等。
我已经设置好了,当 UITableViewCell 被选中时,它会显示与 swift 文件关联的 viewController。然而这意味着我在storyBoard上做了很多viewController。
我怎样才能只有一个 viewController 并根据选择的 UITableViewCell 用来自不同 swift 文件的问题填充它?
我选择调用 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 用各种 swift 文件中的问题填充它。因为当我认为我只能拥有一个时,我有很多 viewController。
【问题讨论】:
【参考方案1】:是的,你是对的 - 看起来你在问题文件表中更改的只是内容,所以你应该有一个带有 tableView 的视图,并根据你想要的问题填充它。
您可能应该将您的问题存储在数据文件中,而不是将它们硬编码为 swift 类,因此请考虑在您的应用程序包或众多轻量级数据库之一中读取和解析文本文件 - Realm 或(可能有点矫枉过正) ) 核心数据。
【讨论】:
谢谢:)。有什么教程或示例可以推荐吗? 我是 Ray Wenderlich 教程的忠实粉丝 - 你应该在这里找到你需要的一切 - raywenderlich.com/tutorials以上是关于根据所选的 UITableViewCell 打开几个 swift 文件之一的主要内容,如果未能解决你的问题,请参考以下文章
业务受理需求 客户下单 根据前台页面所选的省市区 关联定区去生成订单
jsp页面里 怎么让文本输入框的值 根据select所选的值而动态显示出相应的值