I am trying to code images to UIImage but I am having trouble. I am not sure how code it for each different image per list item. The app I am building is a List with pictures attached to each list item.
Below is the MyWhatsit class:
class MyWhatsit { var name: String { didSet { postDidChangeNotification() } } var location: String { didSet { postDidChangeNotification() } } var image: UIImage? { didSet { postDidChangeNotification() } } var viewImage: UIImage { return image ?? UIImage(named: "camera")! } init( name: String, position: String = "" ) { self.name = name self.location = location } func postDidChangeNotification() { let center = NSNotificationCenter.defaultCenter() center.postNotificationName(WhatsitDidChangeNotification, object: self) } } Below is the Table View:
override func numberOfSectionsInTableView(tableView: UITableView) -> Int { return 1 } override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int { return things.count } override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { let cell = tableView.dequeueReusableCellWithIdentifier("Cell", forIndexPath: indexPath) let thing = things[indexPath.row] as MyWhatsit cell.textLabel?.text = thing.name cell.detailTextLabel?.text = thing.location cell.imageView?.image = thing.viewImage return cell } override func tableView(tableView: UITableView, canEditRowAtIndexPath indexPath: NSIndexPath) -> Bool { // Return false if you do not want the specified item to be editable. return true } override func tableView(tableView: UITableView, commitEditingStyle editingStyle: UITableViewCellEditingStyle, forRowAtIndexPath indexPath: NSIndexPath) { if editingStyle == .Delete { things.removeAtIndex(indexPath.row) tableView.deleteRowsAtIndexPaths([indexPath], withRowAnimation: .Fade) } else if editingStyle == .Insert { // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view. } }