UITableViewCell
のカスタムクラスはCustomTableCell
としましょう。 CustomTableCell
であなたはUIImageView
の出口に出ます(imageViewと言う)。 UIButton
の対策を講じてください(btnShow)。
以下の方法を実装します。
まず、あなたのVCでのグローバルな配列を取る、arrSelected
は私達があなたのImageViewのの高さを変更した場合、セルの高さが影響を受けるかをしなければならない
public func tableView(_ tableView: UITableView, estimatedHeightForRowAt indexPath: IndexPath) -> CGFloat{
return UITableViewAutomaticDimension
}
open func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
return UITableViewAutomaticDimension
}
open func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell{
let customCell : CustomTableCell = tableView.dequeueReusableCell(withIdentifier: "cell") as! CustomTableCell
customCell.imageView.tag = indexPath.row;
customCell.btnShow.tag = indexPath.row;
var xPos : CGFloat!
var yPos : CGFloat!
var width : CGFloat!
var height : CGFloat!
xPos = cell.imageView.frame.origin.x
width = cell.imageView.frame.size.width
height = cell.imageView.frame.size.height
if arrSelected.contains(indexPath.row) {
yPos = 100 // whatever the height of imageview when image is present
cell.imageView.isHidden = false
}
else{
yPos = cell.btnShow.frame.size.height
cell.imageView.isHidden = true
}
cell.imageView.frame = CGRect(x: xPos, y: yPos, width: width, height: height)
return customCell
}
// btnShow action
@IBAction func actionbtnShow(_ sender: UIButton) {
if sender.isSelected {
let itemToRemoveIndex = arrSelected.indexOf(sender.tag) {
arrSelected.removeAtIndex(sender.tag)
sender.isSelected = !sender.isSelected
}
else{
arrSelected.append(sender.Tag)
sender.isSelected = !sender.isSelected
}
// reload tableView
}
言いますか? –
reloadData()が呼び出されない限りNo –
あなたのtableviewcellスクリーンショットを提供してください。私たちはあなたが望むものを理解することができますか? –