Search code examples
iosswiftswift4cell

TableViewCell view disappear


I have UITextField at my UItableviewCell , when I click done button on keyboard , my Cell views is removed from Superview

override func layoutSubviews() {
    super.layoutSubviews()
    self.selectionStyle = .none
    line.backgroundColor = .custom_gray()
    line.snp.makeConstraints { (cons) in
        cons.bottom.left.right.equalTo(phone).inset(0)
        cons.height.equalTo(0.5)
    }
    stack.snp.makeConstraints { (cons) in
        cons.left.right.equalTo(self).inset(25)
        cons.centerY.equalTo(self)
        cons.height.equalTo(230)
        cons.bottom.equalTo(self).inset(15)
    }
    stack.dropShadow()
    stack.layoutIfNeeded()
}

Solution

  • I solve this problem By adding my View Into TableviewCell content view

     self.contentView.addSubview(stack)
     phone.delegate = self
     password.delegate = self
     stack.snp.makeConstraints { (cons) in
            cons.left.right.equalTo(self.contentView).inset(25)
            cons.centerY.equalTo(self.contentView)
            cons.height.equalTo(230)
            cons.bottom.equalTo(self.contentView).inset(15)
     }
     self.contentView.backgroundColor = .white
    

    and I return this view from tableviewHeaderContent

    override func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
            let head = tableView.dequeueReusableCell(withIdentifier: headerid) as! ProfileLoginTableViewCell
            return head.contentView
        }