SpreadsheetView icon indicating copy to clipboard operation
SpreadsheetView copied to clipboard

SpreadsheetView inside a expandable custom tableview cell

Open Rufy86 opened this issue 7 years ago • 7 comments

Expected Behavior

see all cell

Actual Behavior

sometime see all cell, sometime see one row less

Steps to Reproduce the Problem

  1. programmatically create a cell in which there are a label and an icon. the cell is expandable at touch of cell. under the label and the icon put the spreadsheet view
  2. populate the spreadsheet view with data stuff
  3. build and run and touch on cell to expand the cell

Specifications

  • Xcode version: 9.0
  • iOS version: 11.0.2
  • Dependency manager + version: Cocoapods last version

I'm trying to create a custom expandable cell in which there is the spreadsheet, because i want to show some information on demand by clicking on cell. the problem is that:

  1. i've some problem with constraints
  2. (the big problem) when click, alternatively you see all cells or one less.

how can I fix it?

That you very much

Rufy86 avatar Oct 08 '17 23:10 Rufy86

@Rufy86 Could you provide a reproducible sample project?

kishikawakatsumi avatar Oct 10 '17 01:10 kishikawakatsumi

@kishikawakatsumi sure!

in this app I've 2 problem:

  1. constraints
  2. last row don't be shown every time spreadSheeTest.zip

Rufy86 avatar Oct 10 '17 10:10 Rufy86

to show the problem: 1) img_1737

img_1740

img_1737 2

img_1738

Rufy86 avatar Oct 10 '17 10:10 Rufy86

I send you the last version of the cell in which there are all component that I want. SpreadsheetView included with the same problem.

the constraints problem still

`import UIKit import SpreadsheetView

class ConjugAdjTableViewCell: UITableViewCell,SpreadsheetViewDelegate,SpreadsheetViewDataSource { var labelText:String = ""{ didSet{ if labelText != oldValue { dictTextLabel.text = labelText } } }

var detailText:String = ""{
    didSet{
        if detailText != oldValue {
            dictDetailTextLabel.text = detailText
        }
    }
}

enum CellState {
    case collapsed
    case expanded
    
    var carretImage: UIImage {
        switch self {
        case .collapsed:
            return #imageLiteral(resourceName: "expand")
        case .expanded:
            return #imageLiteral(resourceName: "collapse")
        }
    }
}

private let expandedViewIndex: Int = 1

var state: CellState = .collapsed {
    didSet {
        toggle()
    }
}

var dictTextLabel = UILabel()
var dictDetailTextLabel = UILabel()
var dictTypeLemmaTextLabel = UILabel()
var dictInfoButton = UIButton()
var expanderImageView = UIImageView()
var spreadSheetView = SpreadsheetView()
var spreadSheet_V:NSLayoutConstraint!
var viewDictionary:[String : Any]!

override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
    super.init(style: style, reuseIdentifier: reuseIdentifier)
    
    
    dictTextLabel = UILabel(frame: CGRect(x: 15, y: 11, width: 90, height: 40))
    dictTextLabel.textAlignment = .right
    dictTextLabel.font = UIFont(name: "HelveticaNeueLTPro-Md", size: 13)
    dictTextLabel.translatesAutoresizingMaskIntoConstraints = false
    dictTextLabel.backgroundColor = .red
    self.contentView.addSubview(dictTextLabel)
    
    dictDetailTextLabel = UILabel(frame: CGRect(x: 99, y: 11, width: 216, height: 40))
    dictDetailTextLabel.textAlignment = .left
    dictDetailTextLabel.numberOfLines = 0
    dictDetailTextLabel.font = UIFont(name: "HelveticaNeueLTPro-Lt", size: 13)
    dictDetailTextLabel.translatesAutoresizingMaskIntoConstraints = false
    dictDetailTextLabel.backgroundColor = .blue
    self.contentView.addSubview(dictDetailTextLabel)
    
    expanderImageView = UIImageView (frame: CGRect(x: 323, y: 7, width: 30, height: 30))
    expanderImageView.translatesAutoresizingMaskIntoConstraints = false
    expanderImageView.backgroundColor = .purple
    self.contentView.addSubview(expanderImageView)
    
    dictTypeLemmaTextLabel = UILabel(frame: CGRect(x: 15, y: 50, width: 314, height: 21))
    dictTypeLemmaTextLabel.textAlignment = .left
    dictTypeLemmaTextLabel.font = UIFont(name: "HelveticaNeueLTPro-Lt", size: 13)
    dictTypeLemmaTextLabel.translatesAutoresizingMaskIntoConstraints = false
    dictTypeLemmaTextLabel.backgroundColor = .yellow
    self.contentView.addSubview(dictTypeLemmaTextLabel)
    
    dictInfoButton = UIButton(frame: CGRect(x: 337, y: 45, width: 30, height: 30))
    dictInfoButton.addTarget(self, action: #selector(self.getInfo(sender:)), for: .touchUpInside)
    dictInfoButton.setImage(UIImage(named: "info"), for: .normal)
    dictInfoButton.translatesAutoresizingMaskIntoConstraints = false
    self.contentView.addSubview(dictInfoButton)
    
    spreadSheetView = SpreadsheetView(frame: CGRect(x: 15, y: 48, width: 300, height: 150))
    spreadSheetView.translatesAutoresizingMaskIntoConstraints = false
    spreadSheetView.dataSource = self
    spreadSheetView.delegate = self
    spreadSheetView.register(HeaderCell.self, forCellWithReuseIdentifier: String(describing: HeaderCell.self))
    spreadSheetView.register(TextCell.self, forCellWithReuseIdentifier: String(describing: TextCell.self))
    spreadSheetView.backgroundColor = .orange
    self.contentView.addSubview(spreadSheetView)
    
    
    viewDictionary = ["textLabel":dictTextLabel, "detailTextLabel":dictDetailTextLabel, "expanderImageView":expanderImageView, "tabella":spreadSheetView, "typeLabel":dictTypeLemmaTextLabel, "infoButton":dictInfoButton] as [String : Any]
    let dictTextLabel_H = NSLayoutConstraint.constraints(withVisualFormat: "H:[textLabel(90)]", options: NSLayoutFormatOptions(rawValue: 0), metrics: nil, views: viewDictionary)
    let dictTextLabel_V = NSLayoutConstraint.constraints(withVisualFormat: "V:[textLabel(34)]", options: NSLayoutFormatOptions(rawValue: 0), metrics: nil, views: viewDictionary)
    let dictTextLabel_POS_H = NSLayoutConstraint.constraints(withVisualFormat: "H:|-15-[textLabel]-8-[detailTextLabel]", options: NSLayoutFormatOptions(rawValue: 0), metrics: nil, views: viewDictionary)
    let dictTextLabel_POS_V = NSLayoutConstraint.constraints(withVisualFormat: "V:|-5-[textLabel]", options: NSLayoutFormatOptions(rawValue: 0), metrics: nil, views: viewDictionary)
    
    let dictDetailTextLabel_V = NSLayoutConstraint.constraints(withVisualFormat: "V:[detailTextLabel(34)]", options: NSLayoutFormatOptions(rawValue: 0), metrics: nil, views: viewDictionary)
    let dictDetailTextLabel_POS_H = NSLayoutConstraint.constraints(withVisualFormat: "H:[detailTextLabel]-8-[expanderImageView]", options: NSLayoutFormatOptions(rawValue: 0), metrics: nil, views: viewDictionary)
    let dictDetailTextLabel_POS_V = NSLayoutConstraint.constraints(withVisualFormat: "V:|-5-[detailTextLabel]", options: NSLayoutFormatOptions(rawValue: 0), metrics: nil, views: viewDictionary)
    
    let expander_H = NSLayoutConstraint.constraints(withVisualFormat: "H:[expanderImageView(30)]", options: NSLayoutFormatOptions(rawValue: 0), metrics: nil, views: viewDictionary)
    let expander_V = NSLayoutConstraint.constraints(withVisualFormat: "V:[expanderImageView(30)]", options: NSLayoutFormatOptions(rawValue: 0), metrics: nil, views: viewDictionary)
    let expander_POS_H = NSLayoutConstraint.constraints(withVisualFormat: "H:[expanderImageView]-8-|", options: NSLayoutFormatOptions(rawValue: 0), metrics: nil, views: viewDictionary)
    let expander_POS_V = NSLayoutConstraint.constraints(withVisualFormat: "V:|-7-[expanderImageView]", options: NSLayoutFormatOptions(rawValue: 0), metrics: nil, views: viewDictionary)
    
    let typeTextLabel_V = NSLayoutConstraint.constraints(withVisualFormat: "V:[typeLabel(21)]", options: NSLayoutFormatOptions(rawValue: 0), metrics: nil, views: viewDictionary)
    let typeTextLabel_POS_H = NSLayoutConstraint.constraints(withVisualFormat: "H:|-15-[typeLabel]", options: NSLayoutFormatOptions(rawValue: 0), metrics: nil, views: viewDictionary)
    let typeTextLabel_POS_V = NSLayoutConstraint.constraints(withVisualFormat: "V:|-49-[typeLabel]", options: NSLayoutFormatOptions(rawValue: 0), metrics: nil, views: viewDictionary)
    
    let dictButton_H = NSLayoutConstraint.constraints(withVisualFormat: "H:[infoButton(30)]", options: NSLayoutFormatOptions(rawValue: 0), metrics: nil, views: viewDictionary)
    let dictButton_V = NSLayoutConstraint.constraints(withVisualFormat: "V:[infoButton(30)]", options: NSLayoutFormatOptions(rawValue: 0), metrics: nil, views: viewDictionary)
    let dictButton_POS_H = NSLayoutConstraint.constraints(withVisualFormat: "H:[typeLabel]-8-[infoButton]-8-|", options: NSLayoutFormatOptions(rawValue: 0), metrics: nil, views: viewDictionary)
    let dictButton_POS_V = NSLayoutConstraint.constraints(withVisualFormat: "V:|-47-[infoButton]", options: NSLayoutFormatOptions(rawValue: 0), metrics: nil, views: viewDictionary)
    
    let spreadSheetView_V = NSLayoutConstraint.constraints(withVisualFormat: "V:[tabella(150)]", options: NSLayoutFormatOptions(rawValue: 0), metrics: nil, views: viewDictionary)
    let spreadSheetView_POS_H = NSLayoutConstraint.constraints(withVisualFormat: "H:|-8-[tabella]-8-|", options: NSLayoutFormatOptions(rawValue: 0), metrics: nil, views: viewDictionary)
    let spreadSheetView_POS_V = NSLayoutConstraint.constraints(withVisualFormat: "V:[infoButton]-3-[tabella]-8-|", options: NSLayoutFormatOptions(rawValue: 0), metrics: nil, views: viewDictionary)
    
    self.dictTextLabel.addConstraints(dictTextLabel_H)
    self.dictTextLabel.addConstraints(dictTextLabel_V)
    self.contentView.addConstraints(dictTextLabel_POS_H)
    self.contentView.addConstraints(dictTextLabel_POS_V)
    
    self.dictDetailTextLabel.addConstraints(dictDetailTextLabel_V)
    self.contentView.addConstraints(dictDetailTextLabel_POS_H)
    self.contentView.addConstraints(dictDetailTextLabel_POS_V)
    
    self.expanderImageView.addConstraints(expander_H)
    self.expanderImageView.addConstraints(expander_V)
    self.contentView.addConstraints(expander_POS_H)
    self.contentView.addConstraints(expander_POS_V)
    
    self.dictTypeLemmaTextLabel.addConstraints(typeTextLabel_V)
    self.contentView.addConstraints(typeTextLabel_POS_H)
    self.contentView.addConstraints(typeTextLabel_POS_V)
    
    self.dictInfoButton.addConstraints(dictButton_H)
    self.dictInfoButton.addConstraints(dictButton_V)
    self.contentView.addConstraints(dictButton_POS_H)
    self.contentView.addConstraints(dictButton_POS_V)
    
    self.spreadSheetView.addConstraints(spreadSheetView_V)
    self.contentView.addConstraints(spreadSheetView_POS_H)
    self.contentView.addConstraints(spreadSheetView_POS_V)
    
    
}

required init?(coder aDecoder: NSCoder) {
    fatalError("init(coder:) has not been implemented")
}

override func awakeFromNib() {
    super.awakeFromNib()
    // Initialization code
}

override func setSelected(_ selected: Bool, animated: Bool) {
    super.setSelected(selected, animated: animated)

    // Configure the view for the selected state
}

private func toggle() {
    expanderImageView.image = state.carretImage
}

private func stateIsCollapsed() -> Bool {
    return state == .collapsed
}

func numberOfColumns(in spreadsheetView: SpreadsheetView) -> Int {
    return 3
}

func numberOfRows(in spreadsheetView: SpreadsheetView) -> Int {
    return 5
}

func spreadsheetView(_ spreadsheetView: SpreadsheetView, cellForItemAt indexPath: IndexPath) -> Cell? {
    if case 0 = indexPath.row {
        let cell = spreadsheetView.dequeueReusableCell(withReuseIdentifier: String(describing: HeaderCell.self), for: indexPath) as! HeaderCell
        cell.label.text = "Prova"
        cell.sortArrow.text = "Header"
        cell.setNeedsLayout()
        return cell
    } else {
        let cell = spreadsheetView.dequeueReusableCell(withReuseIdentifier: String(describing: TextCell.self), for: indexPath) as! TextCell
        cell.label.text = "Cella normale"
        cell.setNeedsLayout()
        return cell
    }
}

func spreadsheetView(_ spreadsheetView: SpreadsheetView, widthForColumn column: Int) -> CGFloat {
    return 100
}

func spreadsheetView(_ spreadsheetView: SpreadsheetView, heightForRow row: Int) -> CGFloat {
    return 30
}

func frozenColumns(in spreadsheetView: SpreadsheetView) -> Int {
    return 1
}

func frozenRows(in spreadsheetView: SpreadsheetView) -> Int {
    return 1
}

@objc func getInfo(sender:UIButton) -> Void {
    print("forse ci siamo")
}

} `

Rufy86 avatar Oct 10 '17 14:10 Rufy86

Is there no solution to this problem?

Rufy86 avatar Dec 22 '17 12:12 Rufy86

@Rufy86 have you solved it, please help me

gy37 avatar Sep 30 '18 01:09 gy37

@Rufy86 have you solved it, please help me

before setup spreadsheetview in cell, set cell's bounds first, then set spreadsheetview.frame explicitly.

    bounds = CGRect(x: 0, y: 0, width: ii_ScreenWidth, height: height)
    addSubview(spreadsheetView)
    spreadsheetView.frame = bounds.insetBy(dx: ii_LeftMargin, dy: ii_TopMargin)

gy37 avatar Sep 30 '18 07:09 gy37