所以我想創建一個tableview和單元格不會顯示出來。除了不向食譜數組添加任何東西,有沒有什麼公然錯誤的代碼?UITableView將不會顯示信息從陣列
如果這意味着什麼,當我嘗試將tableview鏈接到我的代碼時,它不會給我創建插座的機會。 Github link here
我是新來iOS編程,所以這可能是一個愚蠢的問題,對不起,如果是這樣的話。
import UIKit
class ViewController: UIViewController, UITableViewDelegate, UITableViewDataSource {
@IBOutlet weak var tableView: UITableView!
var recipes : [Recipe] = []
override func viewDidLoad() {
super.viewDidLoad()
tableView.dataSource = self
tableView.delegate = self
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = UITableViewCell()
let recipe = recipes[indexPath.row]
cell.textLabel?.text = recipe.title!
return cell
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return recipes.count
}
func createRecipe() -> [Recipe] {
let recipe1 = Recipe()
recipe1.title = "Test"
recipe1.instructions = "testing"
recipe1.time = "testing"
let recipe2 = Recipe()
recipe2.title = "Test2"
recipe2.instructions = "testing"
recipe2.time = "testing"
return [recipe1, recipe2]
}
}
謝謝。
你已經解決了你的錯誤? – Hitesh
@Hitesh是的,問題是我試圖從coreData中拉出而不保存任何內容到coreData。我在下面回答了我自己的問題。感謝您的提交! –