致命错误:意外地发现零,同时展开一个可选值(当添加到阵列)

编程入门 行业动态 更新时间:2024-10-28 11:26:56
本文介绍了致命错误:意外地发现零,同时展开一个可选值(当添加到阵列)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有一些code,从接收赛格瑞价值和替换,我有索引号数组的某一个元素。

I have some code that receives value from a segue and replaces a certain element of an array with the index number that I have.

变量的初始化:

var noteTitles: [String] = ["Sample Note"] var noteBodies: [String] = ["This is what lies within"] var selectedNoteIndex: Int! var newTitle: String! var newBody: String!

和我有一个SEGUE,使得最后的3个值,我想他们是。值​​

and I have a segue that makes the last 3 values the values that I want them to be.

viewDidLoad中()下,我有这样的:

under viewDidLoad(), I have this:

if newTitle == nil && newBody == nil { } else { println("\(newTitle)") println("\(newBody)") println("\(selectedNoteIndex)") let realTitle: String = newTitle let realBody: String = newBody let realIndex: Int = selectedNoteIndex noteTitles[realIndex] = realTitle noteBodies[realIndex] = realBody }

我的日志显示如下:

My logs show this:

New Note Title This is what lies within nil fatal error: unexpectedly found nil while unwrapping an Optional value

和我得到

Thread 1: EXC_BAD_INSTRUCTION(code=EXC_i385_INVOP,subcode=0x0)

就行了。

let realIndex: Int = selectedNoteIndex

谁能告诉我什么,我做错了吗?

Can anyone tell me what I'm doing wrong?

推荐答案

我得到这些错误的原因是因为在segueing返回到主视图,我没有使用正确的开卷SEGUE,而是用另一个节目SEGUE,其中擦除的有previously一直视图控制器内的所有数据。通过创建一个开卷SEGUE,我能够在SEGUE到详细视图和prevent之前保持值的误差。

The reason I was getting these errors is because while segueing back to the main view, I was not using the proper unwind segue, and instead using another show segue, which erased all data that had previously been within the view controller. By creating a unwind segue, I was able to keep the values before the segue to the detail view and prevent the error.

更多推荐

致命错误:意外地发现零,同时展开一个可选值(当添加到阵列)

本文发布于:2023-11-26 12:21:20,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1633914.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:可选   阵列   错误   发现   意外地

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!