【发布时间】:2018-06-07 21:50:26
【问题描述】:
我面临一个动态调整UITableView 行高的问题。我知道通过使用这种方法我们可以实现
self.tableView.rowHeight = UITableViewAutomaticDimension;
self.tableView.estimatedRowHeight = 44.0;
但在我的情况下,我将 XIB 文件用于 UITableViewCell,并且我正在为单元格添加阴影。在这种情况下如何动态添加行高。同时,根据服务器时间,我正在显示和隐藏按钮。所以请任何人都可以建议我如何解决这个问题。这是我的行索引方法的单元格。
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let identifier = "Custom"
var cell: PApplyLeaveTableViewCell! = tableView.dequeueReusableCell(withIdentifier: identifier) as? PApplyLeaveTableViewCell
if cell == nil {
tableView.register(UINib(nibName: "PApplyLeaveTableViewCell", bundle: nil), forCellReuseIdentifier: identifier)
cell = tableView.dequeueReusableCell(withIdentifier: identifier) as? PApplyLeaveTableViewCell
}
cell.selectionStyle = UITableViewCellSelectionStyle.none
cell.contentView.backgroundColor = UIColor.clear
var localDic :NSDictionary!
localDic = totlLeavesArray.object(at: indexPath.row) as! NSDictionary
cell.acknowled_lbl.text = localDic["acknowledgement"] as? String
cell.date_lbl.text = localDic["totalDate"] as? String
cell.reason_lbl.text = localDic["reason"] as? String
let compareDate = localDic["compare"] as? String
if(compareDate == "No")
{
cell.delet_Btn.isHidden = true
cell.edit_Btn.isHidden = true
}
else
{
cell.delet_Btn.isHidden = false
cell.edit_Btn.isHidden = false
}
cell.edit_Btn.tag = indexPath.row
cell.edit_Btn.addTarget(self, action: #selector(PApplyLeaveViewController.EditViewAction(_:)), for:.touchUpInside)
cell.delet_Btn.tag = indexPath.row
cell.delet_Btn.addTarget(self, action: #selector(PApplyLeaveViewController.DeleteAction(_:)), for:.touchUpInside)
let whiteRoundedView : UIView = UIView(frame: CGRect(x: 5, y: 8, width: self.view.frame.size.width - 15, height: 220))
whiteRoundedView.layer.backgroundColor = CGColor(colorSpace: CGColorSpaceCreateDeviceRGB(), components: [1.0, 1.0, 1.0, 0.9])
whiteRoundedView.layer.masksToBounds = false
whiteRoundedView.layer.cornerRadius = 2.0
whiteRoundedView.layer.shadowOffset = CGSize(width: -1, height: 1)
whiteRoundedView.layer.shadowOpacity = 0.2
cell.contentView.addSubview(whiteRoundedView)
cell.contentView.sendSubview(toBack: whiteRoundedView)
cell.contentView.backgroundColor = UIColor.clear
return cell
}
【问题讨论】:
标签: ios iphone swift uitableview row-height