我有一个应用程序,用户可以通过填充表格视图将书籍添加到收藏夹列表中。这本书的详细信息显示在一个视图中,通过点击“收藏夹”,执行一个 segue,将该书的信息输入到 tableview 单元格中。
目前,一次只能在表格中出现一本书添加新书将删除初始条目(因此实际上只使用了 tableview 的第一个单元格)
有没有办法在表格视图中保存每个条目,所以实际上创建了一个收藏夹列表
保存按钮
@IBAction func saveButton(_ sender: Any) {
let bookFormat = formatLabel.text
if (bookFormat!.isEmpty)
{
displayMyAlertMessage(userMessage: "Please Select a Book Format")
return
}
else{
self.performSegue(withIdentifier: "LibViewSegue", sender: self)
}
}
表视图
extension LibrarybookViewController: UITableViewDataSource, UITableViewDelegate{
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
return 115
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
print(#function, dataSource.count)
return dataSource.count
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
print(#function, "indexPath", indexPath)
guard let bookCell = tableView.dequeueReusableCell(withIdentifier: "libCell", for: indexPath) as? LibrarybookTableViewCell else {
return UITableViewCell()
}
let libbook = dataSource[indexPath.row]
bookCell.cellTitleLabel.text = libbook.title
bookCell.cellReleaseLabel.text = libbook.release
bookCell.cellFormatLabel.text = bookFormat
return bookCell
}
我一直在阅读有关默认值和 CoreData 的信息,但我不确定这是否应该在 segue 按钮操作或 tableview 函数中实现?