swift - 待办事项列表 - "right detail"单元格样式以显示项目数

标签 swift xcode uitableview

我正在学习 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/

相关文章:

swift - 如何在 Swift 中从 UIPicker 填充文本字段

iphone - MKAnnotationView viewForAnnotation 从未调用过

ios - 当应用程序切换器出现时,执行命令 Xcode swift

ios - 如何更改 iOS UITextField 中的行数

ios - 在基于标签栏的应用程序上使用 UINavigationController 将数组添加到 UITableView

ios - UITableView headerView 大小不同

ios - 将我的应用程序连接到服务器/JSON/Swift/iOS 的注册机制

swift - UISearchController : how to get selected table row index in ios8 (Swift)

ios - UIViewController 内的 UITableView 不显示

ios - 如何从自定义相册中获取所有图像 - Swift