Skip to content

I modified the UITableViewCell sub class to include subtitle not working #15

Description

I modified the UITableViewCell sub class to include subtitle not working. When I collapse and expand the parent node few times, the detail label text in children is copied to parent. You have not provided your component to include subtitle by default, I need to modify your code, to do that. I hope you have given the screenshot with subtitle example, but your component doesn't have the feature

class CustomUITableViewCell: UITableViewCell
{
    override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
        super.init(style: .subtitle, reuseIdentifier: reuseIdentifier)
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    override func layoutSubviews() {
        super.layoutSubviews();
        
        guard var imageFrame = imageView?.frame else { return }
        
        let offset = CGFloat(indentationLevel) * indentationWidth
        imageFrame.origin.x += offset
        imageView?.frame = imageFrame
        
        
    }
}

detail label as follows in

 func treeView(_ treeView: LNZTreeView, cellForRowAt indexPath: IndexPath, forParentNode parentNode: TreeNodeProtocol?, isExpanded: Bool) -> UITableViewCell {
        
        let node: Node
        if let parent = parentNode as? Node {
            node = parent.children![indexPath.row]
        } else {
            node = root[indexPath.row]
        }
//        var cell: UITableViewCell?
        
        //        let cell = treeView.dequeueReusableCell(withIdentifier: "cell", style: .default, for: node, inSection: indexPath.section)
        var cell = treeView.dequeueReusableCell(withIdentifier: "cell", for: node, inSection: indexPath.section)
        if !node.descriptionText.isEmpty {
            cell.detailTextLabel!.numberOfLines = 2;
            cell.detailTextLabel!.lineBreakMode = .byWordWrapping;
            cell.detailTextLabel!.text = node.descriptionText
            cell.detailTextLabel?.sizeToFit()
        }
        
        if node.isExpandable {
            if node.children!.count > 0 {
            cell.textLabel?.textColor = UIColor.black
            cell.textLabel?.font = UIFont(name:"HelveticaNeue-Bold", size: 16.0)
            }
            if isExpanded {
                cell.imageView?.image = #imageLiteral(resourceName: "index_folder_indicator_open")
            } else {
                cell.imageView?.image = #imageLiteral(resourceName: "index_folder_indicator")
            }
        } else {
            
            cell.textLabel?.textColor = UIColor.darkGray
            cell.textLabel?.font = UIFont(name:"HelveticaNeue-Bold", size: 16.0)
            cell.imageView?.image = nil
        }
        
        cell.textLabel?.text = node.identifier
        
        return cell
    }

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions