Dha*_*esh 0 image uitableview ios swift
我正在开发一个简单的表格应用程序,我想在每个单元格中显示图像,我已经完成了这一步,并在所有单元格中显示一个图像:
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
}
Run Code Online (Sandbox Code Playgroud)
它工作正常,但我想为不同的单元格显示更多图像,并且我已经采用了数组:
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"]
Run Code Online (Sandbox Code Playgroud)
但现在我不知道如何在tableView中为不同的索引显示不同的图像.
我知道在Objective-C中我们可以这样做:
cell.imageView.image = [UIImage imageNamed:[thumbnails objectAtIndex:indexPath.row]];
Run Code Online (Sandbox Code Playgroud)
但是我不知道如何在swift中做到这一点.
请帮帮我.
您可以使用以下代码从数组中获取图像:
cell.imageView?.image = UIImage(named: thumbils[indexPath.row])
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4986 次 |
| 最近记录: |