我想創建一個自定義表格視圖,但偶然發現每個代碼。截至目前,我在下面有這個。這很混亂,可能是錯誤的,但有人可以幫忙嗎?自定義TableView錯誤
另外,我不斷收到一個錯誤代碼
unexpectedly found nil while unwrapping optional value
import UIKit
class tableOutlineViewController: UIViewController, UITableViewDataSource, UITableViewDelegate {
@IBOutlet weak var tableView: UITableView!
var names = ["Max", "Bill", "Reagan", "Mikayla", "Jessie", "Sierra", "Jeff", "Erik", "Landon"]
var numbers = ["35", "33", "29", "27", "25", "23", "19", "15", "11"]
var photo = [UIImage(named: "Person1"), UIImage(named: "Person2"), UIImage(named: "Groceries"), UIImage(named: "Person3"), UIImage(named: "Person4"), UIImage(named: "Person5"), UIImage(named: "Person6"), UIImage(named: "Person7")]
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
public func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return names.count
}
public func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = self.tableView.dequeueReusableCell(withIdentifier: "CustomCell") as! CustomCell
cell.images.image = photo[indexPath.row]
cell.name.text = names[indexPath.row]
cell.number.text = numbers[indexPath.row]
return cell
}
}
你可以添加你CustomCell類的代碼在這裏 –