【发布时间】: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