Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/17.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 从尝试填充表视图中获取SIGABRT_Ios_Swift_Xcode - Fatal编程技术网

Ios 从尝试填充表视图中获取SIGABRT

Ios 从尝试填充表视图中获取SIGABRT,ios,swift,xcode,Ios,Swift,Xcode,我有一个需要用动态数据填充的表视图 我以前是在一个单独的控制器中完成的,只是复制了所有的内容 然而,这一次我不断地得到一个SIGABRT错误。 我发现每当我把这两行错误都包括进来 // editJobTable.dataSource = self // editJobTable.delegate = self 这是我的全视图控制器 import Foundation import UIKit class HelloworkJobsEditJobViewController: UIView

我有一个需要用动态数据填充的表视图

我以前是在一个单独的控制器中完成的,只是复制了所有的内容

然而,这一次我不断地得到一个SIGABRT错误。 我发现每当我把这两行错误都包括进来

//  editJobTable.dataSource = self
//  editJobTable.delegate = self
这是我的全视图控制器

import Foundation
import UIKit

class HelloworkJobsEditJobViewController: UIViewController{
    fileprivate var presenter: HelloworkJobsEditJobPresenter?

    @IBOutlet weak var editJobTable: UITableView!

    func inject(presenter: HelloworkJobsEditJobPresenter) {
        self.presenter = presenter
    }

    var helloworkJob: HelloworkJob!

    override func viewDidLoad(){
        super.viewDidLoad()
        helloworkJob = presenter?.getHelloworkJob()
        editJobTable.dataSource = self
        editJobTable.delegate = self
//        editJobTable.reloadData()
    }

    @IBAction func tapCloseButton(_ sender: Any) {
        self.dismiss(animated: true, completion: nil)
    }
}

extension HelloworkJobsEditJobViewController: UITableViewDataSource {

    func numberOfSections(in tableView: UITableView) -> Int {
        return 1
    }

    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int{
        return 7
    }

    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        print("\(#line): \(#function) \(indexPath.row)")
        let cellIdentifier = "HelloworkJobsEditJobCell"

        guard let cell = tableView.dequeueReusableCell(withIdentifier: cellIdentifier, for: indexPath) as? HelloworkJobsEditJobCell else {
            fatalError("The dequeued cell is not an instance of HelloworkJobsEditJobCell.")
        }

        cell.cellLabel.text = "labeltest"
        cell.cellTextField.text = "textfieldtest"
        return cell
    }
}

extension HelloworkJobsEditJobViewController: UITableViewDelegate {
}

任何关于它为什么会抛出此错误的想法都将不胜感激。

您必须向cell自定义类注册tableView

tableView.register(UINib(nibName: "engineTableViewCell", bundle: nil), forCellReuseIdentifier:"cellID")


必须向单元格自定义类注册tableView

tableView.register(UINib(nibName: "engineTableViewCell", bundle: nil), forCellReuseIdentifier:"cellID")

这样使用:

extension HelloworkJobsEditJobViewController: UITableViewDelegate {

func numberOfSections(in tableView: UITableView) -> Int {
        return 1
    }

    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int{
        return 7
    }
}

extension HelloworkJobsEditJobViewController: UITableViewDataSource {

    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        print("\(#line): \(#function) \(indexPath.row)")
        let cellIdentifier = "HelloworkJobsEditJobCell"

        guard let cell = tableView.dequeueReusableCell(withIdentifier: cellIdentifier, for: indexPath) as? HelloworkJobsEditJobCell else {
            fatalError("The dequeued cell is not an instance of HelloworkJobsEditJobCell.")
        }

        cell.cellLabel.text = "labeltest"
        cell.cellTextField.text = "textfieldtest"
        return cell
    }
}
这样使用:

extension HelloworkJobsEditJobViewController: UITableViewDelegate {

func numberOfSections(in tableView: UITableView) -> Int {
        return 1
    }

    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int{
        return 7
    }
}

extension HelloworkJobsEditJobViewController: UITableViewDataSource {

    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        print("\(#line): \(#function) \(indexPath.row)")
        let cellIdentifier = "HelloworkJobsEditJobCell"

        guard let cell = tableView.dequeueReusableCell(withIdentifier: cellIdentifier, for: indexPath) as? HelloworkJobsEditJobCell else {
            fatalError("The dequeued cell is not an instance of HelloworkJobsEditJobCell.")
        }

        cell.cellLabel.text = "labeltest"
        cell.cellTextField.text = "textfieldtest"
        return cell
    }
}

editJobTable.dataSource=self-editJobTable.delegate=self plus如果正在使用它,则需要在情节提要中设置它。:)该错误向tableview发出了一个很大的信号,即没有将单元格注册到tableview,如下self.tableview.Register(UINib.init(nibName:“CustomCellClassName”,bundle:bundle.main),forCellReuseIdentifier:“cell”)尝试重新连接您的@IBOutlet弱var editJobTable:UITableView!editJobTable.dataSource=self-editJobTable.delegate=self plus如果正在使用它,则需要在情节提要中设置它。:)该错误向tableview发出了一个很大的信号,即没有将单元格注册到tableview,如下self.tableview.Register(UINib.init(nibName:“CustomCellClassName”,bundle:bundle.main),forCellReuseIdentifier:“cell”)尝试重新连接您的@IBOutlet弱var editJobTable:UITableView!我以为这条线就是这么做的
guard let cell=tableView.dequeueReusableCell(带标识符:cellIdentifier,for:indexPath)作为?HelloworkJobsEditJobCell else{fatalError(“出列的单元格不是HelloworkJobsEditJobCell的实例”)}
要使用该行,必须首先注册nib或classI,我认为这是该行所做的
guard let cell=tableView.dequeueReusableCell(带标识符:cellIdentifier,for:indexPath)作为?HelloworkJobsEditJobCell else{fatalError(“出列的单元格不是HelloworkJobsEditJobCell的实例”)}
要使用该行,必须首先注册nib或类