[英]images in tableViewCells that are in Sections (swift 3- Xcode 8.3.2)
Hi I have a table view And want to make it like a picture below 嗨,我有一张桌子,并且想像下面的图片一样
here is the code that I used ( the problem is that I can't see the picture of each cells : 这是我使用的代码(问题是我看不到每个单元格的图片:
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
}
the second problem Is that I want to detect which cells has pressed here is the code that I used But Didn't work : 第二个问题是我想检测这里按下了哪些单元格,这是我使用的但没用的代码:
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")
}
Open Main.storyboard, select the cell and in the Size Inspector change the Row Height to 140 (as per your need-Check in storyboard) Now in viewDidLoad()type this code,use UITableViewAutomaticDimension method: 打开Main.storyboard,选择单元格,然后在Size Inspector中将Row Height更改为140(根据您的需要-在Storyboard中签入)现在在viewDidLoad()中键入以下代码,使用UITableViewAutomaticDimension方法:
tableView.rowHeight = UITableViewAutomaticDimension
tableView.estimatedRowHeight = 140 //as per your need
and mention this reloadData(). 并提及此reloadData()。
self.tableView.reloadData()
More checkout below link: 以下链接提供更多结帐:
https://www.raywenderlich.com/129059/self-sizing-table-view-cells https://www.raywenderlich.com/129059/self-sizing-table-view-cells
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.