【发布时间】:2017-07-06 04:34:13
【问题描述】:
我是 ios 的新手,我正在使用表格视图制作一个项目,其中我扩展了具有 4 个内容视图的表格视图单元格。加载表格时,仅显示第一个内容视图,当我选择行时,所有内容视野扩大。但我也希望在点击第四个内容视图时展开所有内容视图单元格后,我想访问第四个视图的 tapGESTUREAction 方法中的 indexPath.row。 这是我扩展 Cell 的代码,它由 4 个内容视图组成 func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { 打印(YearArr.count) 返回 YearArr.count; }
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cellIdentifier = "Cell"
let cell = tableView.dequeueReusableCell(withIdentifier: cellIdentifier) as! customCell
cell.selectionStyle = .none
cell.lblGrossSal.text = EarnArr[indexPath.row]
cell.lblTotlSal.text = netPayArr[indexPath.row]
cell.lblmonthhName.text = YearArr[indexPath.row]
print(selectedIndex,indexPath.row)
let height = cell.bounds.height
print(height)
return cell;
}
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
let cellIdentifier = "Cell"
let cell = tableView.dequeueReusableCell(withIdentifier: cellIdentifier) as! customCell
cell.selectionStyle = .none
if(selectedIndex == indexPath.row) {
return 190;
return self.calculateHeight(selectedIndexPath: indexPath)
} else {
return 50;
}
}
// fourthView
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
if(selectedIndex == indexPath.row) {
selectedIndex = -1
} else {
selectedIndex = indexPath.row
}
self.expandTableView.beginUpdates()
//self.expandTableView.reloadRows(at: [indexPath], with: UITableViewRowAnimation.automatic )
self.expandTableView.endUpdates()
}
func calculateHeight(selectedIndexPath: IndexPath) -> CGFloat {
let cell = self.expandTableView.cellForRow(at: selectedIndexPath) as! customCell
cell.lblDeductSal.frame = self.cellSummaryLabelFrame(cell: cell, selectedIndexPath: selectedIndexPath)
return 80 + 35 + 21 + 10 + cell.lblDeductSal.frame.size.height + 30
}
func cellSummaryLabelFrame(cell: customCell, selectedIndexPath: IndexPath) -> CGRect {
print(DeductionArr[selectedIndexPath.row])
cell.lblDeductSal.text = DeductionArr[selectedIndexPath.row]
cell.lblDeductSal.numberOfLines = 0
var labelFrame = cell.lblDeductSal.frame
let maxSize = CGSize.init(width: cell.lblDeductSal.frame.size.width, height: CGFloat.greatestFiniteMagnitude)
let requiredSize = cell.lblDeductSal.sizeThatFits(maxSize)
labelFrame.size.height = requiredSize.height
return labelFrame
}
【问题讨论】:
标签: swift tableview cell uitapgesturerecognizer