我需要将图像添加到与 tableView 单元格同名的 tableView 单元格中。即“Boeing”单元使用“Boeing.png”图像。有些图像是 .jpg 格式。
我尝试以与部分和行布局相同的方式添加图像数组。图片与单元格具有相同的名称。我已在我尝试进行更改的位置添加了评论(#1-4)。这应该相当简单,但我看不出我错过了什么。
import UIKit
class NewTableViewController: UITableViewController {
let transportMeans = ["Cars" : ["Ferrari", "Chrysler", "Toyota"], "Trains" : ["Steam", "Diesel", "Electric"], "Planes" : ["AirBus", "Boeing", "Cessna"]]
// #1 added a line for images to be applied:
var transportImages = ["Cars" : ["Ferrari.png", "Chrysler.png","Toyota.png"], "Trains" : ["Steam.png","Diesel.png","Electric.png"], "Planes" : ["AirBus.jpg","Boeing.jpg","Cessna.png"]]
var selectedFileName = ""
struct Objects {
var sectionName : String!
var sectionObjects : [String]!
//#2 added a line for images:
var transportImages : String!
}
var objectArray = [Objects]()
override func viewDidLoad() {
super.viewDidLoad()
// #3 added term 'value' to key:
for (key, value, value) in transportMeans {
print("\(key) -> \(value) -> \(value)")
//#4 added a line for 'transportImages' in the append section-------:
objectArray.append(Objects(sectionName: key, sectionObjects: value, transportImages: value))
}
}
我使用这段代码遇到的错误是:
“源文件中的编辑器占位符”,“'(key: String, value: [String])' 无法转换为 '(_, _, _)',元组具有不同数量的...”,“定义冲突与之前的……”
@ 线:
,
'for (key, value) in TransportMeans {'
,