gpt4 book ai didi

swift - EXC_BAD_INSTRUCTION 评估 bool 比较

转载 作者:行者123 更新时间:2023-11-30 14:00:56 27 4
gpt4 key购买 nike

我不明白 Swift 中的崩溃

func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
if (homeChosen == true && section > 0 && indexChosen + offset == section) {

EXC_BAD_INSTRUCTIONcode = EXC_1386_INVOP_subcode 0x0

在方法的第一行。

homechosen 定义为

var indexChosen = 0
var homeChosen:Bool! at the top of the class

为什么会崩溃?

隔离到:

                if (indexChosen + offset == section) {

比较 Int + Int == Int 是否崩溃。索引选择为 0。

最佳答案

根据错误,我猜测值indexChosen和/或offset不是您所期望的,并且添加语句导致发生翻转。您可以通过从 if 语句中删除数学并检查崩溃是否专门发生在数学中来验证这一点:

func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
let newIndex = indexChosen + offset
if (homeChosen == true && section > 0 && newIndex == section) {

如果崩溃发生在添加的线路上,see my answer to this question .

关于swift - EXC_BAD_INSTRUCTION 评估 bool 比较,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33005069/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com