I have a struct to store name and image names of pictures which are already bundled in app as follows
struct City { var name: String
var imageName: String }
class firstViewController: UIViewController
let cities = [City(name:"City00", imageName:"city_00"),
City(name:"City01", imageName:"city_01"),
City(name:"City02", imageName:"city_02")]
In displayViewController, I have a variable nowCityImages to store data selected from firstViewcontroller
class displayViewController: UIViewController, UITableViewDataSource, UITableViewDelegate, NSFetchedResultsControllerDelegate {
var nowCityImages: [String] = []
Now I want to display image of city in tableview
public func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell
{
let myCell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath) as! CityCell
let outCityImages = nowCityImages[indexPath.item]
// This is not displaying any images
myCell.cityImage.image = UIImage(named:outCityImages)
return myCell
}
If I use print(outCityImages), I am getting following output as excepted
City00
City02
but I don't know how to replace City00 with city_00 and City02 with city_02 in tableview cell so that it displays the image.