我正在学习 swift 和 IOS 开发,我正在创建一个待办事项列表,我试图在其中以正确的详细信息单元格样式显示类别中的项目数。尽管有 3 个或更多,但当它运行它的节目时,我已经设法让它工作,因为它在类别中有 0 个项目。
我正在使用领域来保存我的数据,并且我有一个单独的 CategoryViewController
和一个 TodoListViewController
。
有人能帮帮我吗?我不知道哪里出了问题,我花了好几天才走到这一步!
类别 View Controller :
class CategoryViewController: SwipeTableViewController {
let realm = try! Realm()
var categoryarray: Results<Category>?
var todoItems: Results<Item>?
var todoVC = TodoListViewController()
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = super.tableView(tableView, cellForRowAt: indexPath)
if let category = categoryarray?[indexPath.row] {
cell.textLabel?.text = category.name
cell.backgroundColor = UIColor(hexString: category.colour)
cell.textLabel?.textColor = ContrastColorOf(UIColor(hexString: category.colour)!, returnFlat: true)
cell.detailTextLabel?.text = "\(todoItems?.count ?? 0)"
}
最佳答案
您可能想显示特定类别的项目数量。所以就像设置名称等一样。将 detailTextLabel
的文本设置为 Category
cell.detailTextLabel?.text = String(category.todoItems.count)
关于swift - 待办事项列表 - "right detail"单元格样式以显示项目数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53569602/