所以我想创建一个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。我在下面回答了我自己的问题。感谢您的提交! –