我正在尝试创建一个提醒应用程序,但是当我添加一个类别时,该类别的名称会显示在单元格中,但描述不会显示,并且该单元格会显示两次
//this is in the view controller that has the table view
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return allCategories[section].activities.count
}
//sets the title of the cell to the name of the activity and the subtitle to the description of the activity
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "theCell", for: indexPath)
cell.textLabel?.text = allCategories[indexPath.section].activities[indexPath.row].name
cell.detailTextLabel?.text = allCategories[indexPath.section].activities[indexPath.row].description
return cell
}
//this is in the view controller that creates an activity which populates activities
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if segue.identifier == "createSegue" {
if activityName.text?.isEmpty == false {
if let activityReminder = activityName.text {
allCategories[addButton.tag].activities.append(Activity(name: activityReminder, description: activityDesc.text!, date: datePicker.date))
}
}
}
}
@IBAction func createP(_ sender: Any) {
performSegue(withIdentifier: "createSegue", sender: self)
}
//this populates allCategories
@IBAction func createPressed(_ sender: Any) {
guard categoryNameTF.text == "" else {
allCategories.append(Categories(name: categoryNameTF.text!, description: categoryDescription.text!, activities: []))
dismiss(animated: true, completion: nil)
icon = currentIcon
return
}
}