部分中的 tableViewCells 中的图像 (swift 3- Xcode 8.3.2)
images in tableViewCells that are in Sections (swift 3- Xcode 8.3.2)
您好,我有一个 table 视图并希望将其制作成下面的图片
这是我使用的代码(问题是我看不到每个单元格的图片:
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、select 单元格并在大小检查器中将行高更改为 140(根据您的需要-在故事板中签入)
现在在 viewDidLoad() 中键入此代码,使用 UITableViewAutomaticDimension 方法:
tableView.rowHeight = UITableViewAutomaticDimension
tableView.estimatedRowHeight = 140 //as per your need
并提及此 reloadData()。
self.tableView.reloadData()
更多结帐如下link:
https://www.raywenderlich.com/129059/self-sizing-table-view-cells
您好,我有一个 table 视图并希望将其制作成下面的图片
这是我使用的代码(问题是我看不到每个单元格的图片:
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、select 单元格并在大小检查器中将行高更改为 140(根据您的需要-在故事板中签入) 现在在 viewDidLoad() 中键入此代码,使用 UITableViewAutomaticDimension 方法:
tableView.rowHeight = UITableViewAutomaticDimension
tableView.estimatedRowHeight = 140 //as per your need
并提及此 reloadData()。
self.tableView.reloadData()
更多结帐如下link:
https://www.raywenderlich.com/129059/self-sizing-table-view-cells