Uitableview 如何在tableview的第一个单元格中添加图像,其余的都是字符串
如何在firstCell中添加图像,其余单元格是cellForRowAt:indexPath中的字符串Uitableview 如何在tableview的第一个单元格中添加图像,其余的都是字符串,uitableview,swift3,Uitableview,Swift3,如何在firstCell中添加图像,其余单元格是cellForRowAt:indexPath中的字符串 class ViewController: UIViewController,UITableViewDataSource,UITableViewDelegate { var names = ["jan","feb","mar"] let image = UIImage.init(named: "dine001") @IBOutlet weak var tableview: UITableVie
class ViewController: UIViewController,UITableViewDataSource,UITableViewDelegate {
var names = ["jan","feb","mar"]
let image = UIImage.init(named: "dine001")
@IBOutlet weak var tableview: UITableView!
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return names.count
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "Cell")
cell?.textLabel?.text = names[indexPath.row]
return cell!
}
let cell = tableView.dequeueReusableCell(withIdentifier: "Cell")
if indexPath.row == 0 {
cell.imageView.image = self.image
} else {
cell.textLabel.text = names[indexPath.row]
}