你好,我有一个表格 View ,我想把它做成下图所示
这是我使用的代码(问题是我看不到每个单元格的图片:
var menuImage = ["Add.png" , "Menu.png" , "Add.png" , "Add.png" , "Add.png" , "Add.png" ]
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = UITableViewCell()
cell.textLabel!.text = listSetting[indexPath.section][indexPath.row]
cell.preservesSuperviewLayoutMargins = false
cell.separatorInset = UIEdgeInsets.zero
cell.layoutMargins = UIEdgeInsets.zero
cell.textLabel?.textAlignment = .right
cell.textLabel?.font = UIFont.init(name: "IRANSans", size: 14)
cell.imageView?.image = UIImage.init(named: menuImage[indexPath.row])
return cell
}
第二个问题是我想检测哪些单元格按下了这里是我使用但没有用的代码:
func tableView(_ tableView: UITableView, didSelectRowAt listSetting: IndexPath) {
print("Remove Adds")
if listSetting.section == 1 && listSetting.row == 1{
//Code to implement View Controller to remove adds
print("Cell4 pressed")
}
最佳答案
打开 Main.storyboard,选择单元格并在 Size Inspector 中将 Row Height 更改为 140(根据您的需要 - Check in storyboard) 现在在 viewDidLoad() 中输入这段代码,使用 UITableViewAutomaticDimension 方法:
tableView.rowHeight = UITableViewAutomaticDimension
tableView.estimatedRowHeight = 140 //as per your need
并提到这个 reloadData()。
self.tableView.reloadData()
更多结帐链接如下:
https://www.raywenderlich.com/129059/self-sizing-table-view-cells
关于ios - 部分中的 tableViewCells 中的图像(swift 3- Xcode 8.3.2),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43692703/