我创建了一个包含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