lundi 29 décembre 2014

Update UIImage in UITableView

I've created a custom UITableView cell containing a UIImage and a few labels. I have tagged the UIImage as 100 and have been attempting to update it as follows:



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.
}

}


How should I be updating the UIImage? I currently get a EXC_BAD_INSTRUCTION error when I run my app.




Aucun commentaire:

Enregistrer un commentaire