【发布时间】:2014-12-10 07:59:18
【问题描述】:
我正在开发一个简单的表格应用程序,我想在每个单元格中显示图像,我已经这样做了,一个图像显示在所有单元格中:
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
}
它工作正常,但我想为不同的单元格显示更多图像,并且我已经采用了数组:
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"]
但现在我不知道如何在 tableView 中为不同的索引显示不同的图像。
我知道在 Objective-C 中我们可以这样做:
cell.imageView.image = [UIImage imageNamed:[thumbnails objectAtIndex:indexPath.row]];
但我不知道如何快速做到这一点。
请帮帮我。
【问题讨论】:
标签: ios image uitableview swift