2017-04-10 89 views
0
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! 
} 

如何在firstCell添加圖像,剩下的細胞串如何在tableview中第一個單元格添加圖像,它們的其餘部分都是字符串

回答

0

在你cellForRowAt:indexPath:

let cell = tableView.dequeueReusableCell(withIdentifier: "Cell") 

if indexPath.row == 0 { 
    cell.imageView.image = self.image 
} else { 
    cell.textLabel.text = names[indexPath.row] 
} 
相關問題