[英]How to display different images on tableview at a time by doing JSON Pasing in iOS?
[英]How to display Different Images for different Index in TableView?
我正在開發一個簡單的表格應用程序,我想在每個單元格中顯示圖像,並且已經在所有單元格中顯示一個圖像:
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]];
但是我不知道如何迅速做到這一點。
請幫我。
您可以使用以下代碼從數組中獲取圖像:
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.