我創建了一個包含UIImage和一些標籤的自定義UITableView單元。我已經將UIImage標記爲100,並且一直試圖將其更新如下:在UITableView中更新UIImage
import UIKit
class SecondViewController: UIViewController, UITableViewDelegate, UITableViewDataSource {
@IBOutlet weak var tableView: UITableView!
let Items = ["Altitude","Distance","Groundspeed"]
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return self.Items.count
}
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
var cell:UITableViewCell = self.tableView.dequeueReusableCellWithIdentifier("cell") as UITableViewCell
cell.textLabel?.text = self.Items[indexPath.row]
var CellImageView: UIImageView? = cell.viewWithTag(100) as UIImageView?
CellImageView!.image = UIImage(named: "Airspeed")
return cell
}
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
self.tableView.registerClass(UITableViewCell.self, forCellReuseIdentifier: "cell")
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
我應該如何更新UIImage?當我運行我的應用程序時,我目前得到一個EXC_BAD_INSTRUCTION錯誤。
我只是困惑,爲什麼我需要第二類?爲什麼我不能使用在界面構建器中生成的ID在第一個類中引用我的UIImageView?如果可以的話,我寧願把所有東西都放在一個班級裏。 – user3185748