【问题标题】:TableView is not displayed how it's supposed toTableView 未按应有的方式显示
【发布时间】:2018-06-23 16:06:27
【问题描述】:

我在 Xcode 中创建了一个表格视图,当我运行该项目时,它的显示效果非常好(与图片相关)。 不知道可能是什么问题。 我所做的是:

import UIKit

class ViewController: UIViewController, UITableViewDelegate, UITableViewDataSource {
    let fruit = ["Apple", "Prune", "Grapes", "Watermelon", "Melon", "Cherry"]

    @IBOutlet weak var tableView: UITableView!

    override func viewDidLoad() {
        super.viewDidLoad()

        tableView.delegate = self
        tableView.dataSource = self
    }

    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return fruit.count
    }

    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCell(withIdentifier: "customCell") as! FruitTableViewCell

        cell.fruitLable.text = fruit[indexPath.row]
        cell.fruitImage.image = UIImage(named: fruit[indexPath.row])

        return cell
    }
}

import UIKit

class FruitTableViewCell: UITableViewCell {
    @IBOutlet weak var fruitView: UIView!
    @IBOutlet weak var fruitImage: UIImageView!
    @IBOutlet weak var fruitLable: UILabel!

    override func awakeFromNib() {
        super.awakeFromNib()
    }

    override func setSelected(_ selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)
    }
}

【问题讨论】:

  • 没有附加图片
  • 请附上图片
  • 顺便说一句——不要对你的电脑屏幕拍照。模拟器可以很容易地截取屏幕截图。文件 |新屏幕截图。
  • 你需要添加委托 func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {}

标签: ios swift uitableview


【解决方案1】:

你需要实现heightForRowAt

func tableView(_ tableView: UITableView,heightForRowAt indexPath: IndexPath) -> CGFloat {
    return 200
}

【讨论】:

  • 我做到了,整体看起来更好,但仍然看不到文字附近的图像。
  • 您可以增加高度或谷歌如何使用自动表格单元格
  • 感谢您的信息。无论如何,那些投票给我的人,是地球上最后的利己主义者。你为什么不想想那些你做的人?他们最终因为自私而被阻止提问。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-05-22
  • 1970-01-01
  • 2012-01-31
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多