【发布时间】:2016-01-25 03:07:57
【问题描述】:
我的应用程序有一个带有 tableview 的 VC,其中包含 10 个单元格(问题)。用户选择适用于他们的任何内容,然后按"next" 按钮。然后,它转到下一个 VC 有一个表视图并初始化问题的相应部分。
例如,如果我从 10 个问题中选择“问题 1,问题 2”,那么它应该创建两个标题为“问题 1”和“问题 2”的部分。
现在我添加一个在数组中选择的问题,如下所示:
func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
result.append(allCriteria[indexPath.row])
}
然后,当按下"next" 按钮时,它会将result 数组传递给下一个VC。根据数组“result”的传递,按顺序初始化各个部分。
问题是如果我按随机顺序按问题,它会改变部分的顺序。这是意料之中的。 有办法解决吗?
简而言之,即使用户按"Question2, Question1" 的顺序选择问题,我也希望按"Question1, Question2" 的顺序制作部分
result 数组是[Question]! 的类型,Question class 如下所示:
class Question {
var documents: [Document] = []
var title: String
var description: String
init(dict: [String:AnyObject] ) {
// parse dict to generate a bunch of documents, add them to self.documents
self.title = dict["Title"] as! String
self.description = dict["Description"] as! String
let documentsDicts = dict["Documents"] as! [Dictionary<String,AnyObject>]
for dictionary in documentsDicts {
let document = Document(dict: dictionary)
self.documents.append(document)
}
}
}
【问题讨论】:
标签: ios arrays swift uitableview