我是Swift和iOS编程的新手,所以你不得不原谅这个简单的问题.
我创建了一个tableView,只需按一下按钮即可显示数组(字符串)的内容.现在,我想在tableView部分中"分组"这些字符串,按日期排序.
更详细:当用户点击按钮时,字符串应插入数组的索引0,并显示在具有今日日期标题的部分中.如果数组中的值早于今天的日期,则这些值应显示在该日期的单独部分中.每个部分应对应24小时工作日,并显示当天添加的所有字符串.
这是我到目前为止所取得的一些示例代码:
var testArray[String]()
var sectionsInTable[String]()
@IBOutlet weak var testTable: UITableView!
@IBAction func saveButton(sender: AnyObject) {
testArray.insert("\(strTest)", atIndex: 0)
testTable.reloaddata()
}
func numberOfSectionsInTableView(tableView: UITableView) -> Int {
return sectionsInTable.count
}
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int{
return testArray.count
}
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
var cell = UITableViewCell(style: UITableViewCellStyle.Default, reuseIdentifier: "Cell")
cell.textLabel.text = String(testArray[indexPath.row])
return cell
}
Run Code Online (Sandbox Code Playgroud)
我真的不知道如何管理部分.希望有人可以指出我正确的方向.谢谢!