Я полный новичок в программировании 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
}
Я действительно не знаю, как управлять частью раздела. Надеюсь, кто-то может указать мне в правильном направлении. Спасибо!