ios - 部分中的 tableViewCells 中的图像(swift 3- Xcode 8.3.2)

标签 ios uitableview swift3 intersection

你好,我有一个表格 View ,我想把它做成下图所示

TableView with Sections

这是我使用的代码(问题是我看不到每个单元格的图片:

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/

相关文章:

swift3 - 在 Swift3 中使用 SwiftyJSON

ios - 第一次加载时自动选择项目

ios - Observable.empty 在 zip 中返回什么?

ios - 用户控制的围绕球体运行的 SceneKit 对象在两极表现异常

ios - viewWillAppear 期间的静态 UITableViewCell 更改未反射(reflect)在显示中

ios - 如何在不隐藏分隔符的情况下更改单元格文本颜色?

ios - 将 View Controller 保持在与左侧相同的位置

ios - 警告 : expression implicitly coerced from 'String?' to Any

ios - 如何为 iphone 5 和 iphone 6 创建不同的约束

ios - NSArray* excludedActivities 即使在使用 ARC 并将其设置为 nil 时也会泄漏内存