patrikbelis
patrikbelis

Reputation: 1360

UIImage View in TableView Swift

im doing tableview controller with images and i used this code

override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
    var cell = self.tableView.dequeueReusableCellWithIdentifier("cell") as UITableViewCell

    var program : Program

    program = programy[indexPath.row]

    cell.textLabel?.text = program.name
    cell.accessoryType = UITableViewCellAccessoryType.DisclosureIndicator

    var imageName = UIImage(named: programy[indexPath.row])
    cell.imageView?.image = imageName

and im getting error in

var imageName = UIImage(named: programy[indexPath.row])

Cannot invoke 'init' with an argument list of type (named $T5)

Upvotes: 1

Views: 1497

Answers (2)

zisoft
zisoft

Reputation: 23078

You already get the name of the image from your array in the code above, so you might want to use it for the UIImage inintalization, too:

var imageName = UIImage(named: program.name) 

Upvotes: 1

Andrew Toth
Andrew Toth

Reputation: 419

We can see that programy contains Program types. UIImage(named: String) expects a String so you need to give that Program.name or Program.category. Try this

var imageName = UIImage(named: program.name)

Upvotes: 0

Related Questions