[英]How to display Different Images for different Index in TableView?
I am developing a simple table app where I want to display Image in every cell and I have done this and one Image is displayed In all cells : 我正在开发一个简单的表格应用程序,我想在每个单元格中显示图像,并且已经在所有单元格中显示一个图像:
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell{
// Create the cell
var cell : UITableViewCell = self.TableViewData.dequeueReusableCellWithIdentifier("Cell") as UITableViewCell
cell.textLabel?.text = self.iteams[indexPath.row]
cell.imageView?.image = UIImage(named: "creme_brelee.jpg")
return cell
}
It works fine but I want to display more Images for different cell and for that I have taken on array: 它工作正常,但我想显示更多针对不同单元格的图像以及为此我在数组上拍摄的图像:
var thumbils : [String] = ["egg_benedict.jpg", "mushroom_risotto.jpg", "full_breakfast.jpg", "hamburger.jpg", "ham_and_egg_sandwich.jpg", "creme_brelee.jpg", "white_chocolate_donut.jpg", "starbucks_coffee.jpg", "vegetable_curry.jpg", "instant_noodle_with_egg.jpg", "noodle_with_bbq_pork.jpg", "japanese_noodle_with_pork.jpg", "green_tea.jpg", "thai_shrimp_cake.jpg", "angry_birds_cake.jpg", "ham_and_cheese_panini.jpg"]
but now I dont know how to display different image for different index in tableView. 但是现在我不知道如何在tableView中为不同的索引显示不同的图像。
I know In objective-C we can do like this: 我知道在Objective-C中我们可以这样做:
cell.imageView.image = [UIImage imageNamed:[thumbnails objectAtIndex:indexPath.row]];
But I don't know how to do this in swift. 但是我不知道如何迅速做到这一点。
Please help me for this. 请帮我。
您可以使用以下代码从数组中获取图像:
cell.imageView?.image = UIImage(named: thumbils[indexPath.row])
使用以下代码
cell.imageView?.image = UIImage(self.iteams(indexPath.row)
var imagesArray = [UIImage]()
imagesArray.append(UIImage(named: "mypic.png")!)
cell.imageView?.image = imagesArray[indexPath.row]
return cell
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.