Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/108.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 Swift—在控制器之间传递CoreData时发生致命错误_Ios_Swift_Core Data - Fatal编程技术网

Ios Swift—在控制器之间传递CoreData时发生致命错误

Ios Swift—在控制器之间传递CoreData时发生致命错误,ios,swift,core-data,Ios,Swift,Core Data,这里我有两个表视图控制器,名为:customerTableViewController和customOrderListTableViewController。当单击customerTableViewController中的单元格时,我尝试将核心数据从customerTableViewController传递到customOrderListTableViewController。我通过故事板制作了一段“showCustomerOrderList” 但是目标控制器中的数据总是打印出来的 “致命错误:

这里我有两个表视图控制器,名为:
customerTableViewController
customOrderListTableViewController
。当单击
customerTableViewController
中的单元格时,我尝试将核心数据从
customerTableViewController
传递到
customOrderListTableViewController
。我通过故事板制作了一段“showCustomerOrderList”

但是目标控制器中的数据总是打印出来的

“致命错误:在展开可选文件时意外发现零。” 价值观

当我使用传入的报复性实体属性时。我如何修复此问题? 代码如下:

//in customerTableViewController:
import CoreData
var customer: [Customer] = []    
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
    if segue.identifier == "showCustomerOrderList" {
        let controller = segue.destination as! customOrderListTableViewController
        controller.customer = customer[(tableView.indexPathForSelectedRow?.row)!]
    }
//in customOrderListTableViewController:
import CoreData
     var customer: Customer!
override func viewDidLoad() {
    super.viewDidLoad()
    print("\(self.customer.customerName)")  //error here: Fatal error: Unexpectedly found nil while unwrapping an Optional value
}

在prepare方法中更正目标视图控制器的名称。请编写“customerOrderListTableViewController”而不是“customOrderListTableViewController”,很抱歉在编写过程中出现此类型的错误。其:customOrderListTableViewControllerCheck if
prepare(对于segue:sender:)调用
,并检查它是否在
func viewDidLoad()之后
。如果是在之后,您将Segue从
UITableViewCell
连接到
customOrderListTableViewController
。相反,将其移除,将其从
customerTableViewController
连接到
customOrderListTableViewController
,并实现didSelectRowAtIndexPath并在那里执行检查。非常感谢感谢您的帮助!通过跟踪您的评论进行跟踪,现在就可以了!