Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/104.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/19.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 未调用Journal-DispatchQueue-self.tableView.reloadData()_Ios_Swift_Xcode - Fatal编程技术网

Ios 未调用Journal-DispatchQueue-self.tableView.reloadData()

Ios 未调用Journal-DispatchQueue-self.tableView.reloadData(),ios,swift,xcode,Ios,Swift,Xcode,我刚刚开始,并已经把另一个列表应用程序,因为那里没有足够的。。。但我遇到了一个问题,在为日志输入新条目后,不会调用reloadData()。如果我在XCode中重新编译应用程序,那么新条目就会出现在tableView上 我已经包括了在重新编译应用程序时出现的信号1 SIGTERM错误 import Foundation import UIKit import CoreData class TableViewController: UITableViewController { @I

我刚刚开始,并已经把另一个列表应用程序,因为那里没有足够的。。。但我遇到了一个问题,在为日志输入新条目后,不会调用reloadData()。如果我在XCode中重新编译应用程序,那么新条目就会出现在tableView上

我已经包括了在重新编译应用程序时出现的信号1 SIGTERM错误

import Foundation
import UIKit
import CoreData


class TableViewController: UITableViewController {

    @IBAction func addNewItem(_ sender: Any) {
        return
    }

    @IBOutlet var entityTableView: UITableView!


    var items: [Entity] = [] //Should be same name as new Entity in the dataModel
    let context = (UIApplication.shared.delegate as! AppDelegate).persistentContainer.viewContext


    //Calls the getData which will fetch the new entry and then reload the view
    //The register will linkt he UITableViewCell class with the tableView
    //estimatedRowHeight and rowHeight define the label size and I intentionally want text cut off (journal entries might be quite long) so a preview works
    override func viewDidLoad() {
        super.viewDidLoad()
        self.tableView.estimatedRowHeight = 60
        self.tableView.rowHeight = UITableView.automaticDimension
    }

    //Will reload the table every time that the view is shown to allow it to show the most recent entries
    override func viewWillAppear(_ animated: Bool) {
        getData()
        print ("\(items)")
        NSFetchRequest<NSManagedObject>(entityName: "entry")
    }

    //Func will get the data. Print to check that data has been pulled and then refreshes the
    func getData() {
        do {
            items = try context.fetch(Entity.fetchRequest())
            print (items)
            DispatchQueue.main.async {
                self.tableView.reloadData()
            }
        } catch {
            print("Unable to fetch the data")
        }
    }
}

extension TableViewController {

    //Will have the items presented as most recent on the top
    override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCell(withIdentifier: "Cell", for: indexPath) as UITableViewCell

        cell.textLabel?.text = items.reversed()[indexPath.row].newEntry

        return cell
    }

    override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return items.count
    }

    override func tableView(_ tableView: UITableView, trailingSwipeActionsConfigurationForRowAt indexPath: IndexPath) -> UISwipeActionsConfiguration? {
        let DeleteAction = UIContextualAction(style: .destructive, title: "Delete", handler: { (action, view, success) in
            print("Delete")
        })
        DeleteAction.backgroundColor = .red

        let item = self.items [indexPath.row]
        self.context.delete(item)
        (UIApplication.shared.delegate as! AppDelegate).saveContext()

        self.items.remove(at: indexPath.row)
        tableView.deleteRows(at: [indexPath], with: .fade)
        return UISwipeActionsConfiguration(actions: [DeleteAction])
    }
}
[(实体:实体;
id:0xcae729498383650b
;数据:
),(实体:
实体;id:0xcae72949838f650b
;数据:
)][(实体:
实体;id:0xcae729498383650b
;数据:
),(实体:
实体;id:0xcae72949838f650b
;数据:
)]2019-12-18 14:56:25.896548+0800日记账(核心
数据)[12470:652660][警告]仅警告一次:检测到以下情况:
约束模糊地表示表视图的高度为零
单元格的内容视图。我们正在考虑这场意外的崩溃
改为使用标准高度。单元格:


在“TableViewController”文件中 替换
var项:[实体]=[]

用这个

var items: [Entity] = []{
        didSet{
            DispatchQueue.main.async {
                self.tableView.reloadData()
            }
        }
    }

这将在每个新条目上重新加载tableView。在此之后,您不需要在控制器中的任何位置添加
tableView.reloadData()

刚刚添加了它,但恐怕仍然面临同样的问题。现在我在“NSFetchRequest(entityName:“entry”)”行收到一条错误消息,错误结果是“NSFetchRequest”初始值设定项未使用
var items: [Entity] = []{
        didSet{
            DispatchQueue.main.async {
                self.tableView.reloadData()
            }
        }
    }