我的代碼如下列出了uitableview單元格(a和b)上的兩件事情。我想要一個gif在顯示「a」的單元格上顯示一次。如果else聲明依賴於數組元素(swift3)
import UIKit
class ViewController: UIViewController {
var i1 = ["a","b"]
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return i1.count
}
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath)
cell.textLabel?.textAlignment = .center
cell.textLabel?.text = pets[indexPath.row]
//what I am trying to do but does not work. if the cell reads a I want the cell to display a image.
if i1[0] {
cell.imageView?.loadGif(name: "ftf")
}
return cell
}}
你寫的「a」是什麼意思? –