Swift会使每个内存地址跳转崩溃

问题描述 投票:2回答:1

在过去的三个小时里,这一直困扰着我,但我似乎并没有动脑筋。

我有以下IBOutlet:

@IBAction func simulateTheDay(sender: UIButton) {
    if( self.iceCubesUsing == 0 || self.lemonsUsing == 0){
        showAlertMessage(message: "You need to use at least one lemon or ice cube")
    }

    var numberOfCustomers = 0;
    var winnings = 0;

    self.lemonToIceCubeRatio = self.lemonsUsing / self.iceCubesUsing
    self.lemonsToPurchase = 0
    self.iceCubesToPurchase = 0
    self.lemonsUsing = 0
    self.iceCubesUsing = 0
    self.customers = [];

    do{
        numberOfCustomers = Int(arc4random_uniform(UInt32(11)));
    }while( numberOfCustomers == 0)

    for(var i=0;i<numberOfCustomers;i++){
        self.customers.append(Customer(preference: Double(arc4random_uniform(UInt32(101)))/101.0))
    }
    winnings = standBrain.calculateWinnings(self.customers, acidity: self.lemonToIceCubeRatio)
    self.money += winnings

    updateAssets()
}

无论身在何处。是我班上的一个全局变量。每当我单击与此插座相连的按钮时,应用程序就会崩溃并在顶部突出显示我的if()语句,并说“ EXC_BAD_INSTRUCTION(code = EXCI386_INVOP,subcode = 0x0)”

如果我将相同的代码复制到另一个IBAction中,则效果很好。奇怪的地方来了。如果删除带有内容的if语句,它将在我的while语句中崩溃。如果我删除了它,它将在我的for语句中崩溃。如果我什至删除了它,它也会在函数结尾崩溃,在所有情况下都出现相同的错误消息。

如果我只离开:showAlertMessage(message: "You need to use at least one lemon or ice cube")它似乎没有跳到我的功能。

我尝试删除IBOutlet并重新创建它,尝试在我的情节提要中创建一个新的UIButton,并将其链接到一个新的IBOutlet,尝试清理该项目,并尝试在iOS Simulator中清除所有设置和数据。似乎没有任何效果。

这里是以前的堆栈跟踪,如果有帮助的话。

LemonadeStand`@objc LemonadeStand.ViewController.simulateTheDay (LemonadeStand.ViewController)(ObjectiveC.UIButton) -> () at ViewController.swift:
0x10466a800:  pushq  %rbp
0x10466a801:  movq   %rsp, %rbp
0x10466a804:  subq   $0x30, %rsp
0x10466a808:  movq   %rdx, -0x8(%rbp)
0x10466a80c:  movq   -0x8(%rbp), %rdx
0x10466a810:  movq   %rdi, -0x10(%rbp)
0x10466a814:  movq   %rdx, %rdi
0x10466a817:  movq   %rsi, -0x18(%rbp)
0x10466a81b:  movq   %rdx, -0x20(%rbp)
0x10466a81f:  callq  0x10466e1a4               ; symbol stub for: objc_retain
0x10466a824:  movq   -0x10(%rbp), %rdi
0x10466a828:  movq   %rax, -0x28(%rbp)
0x10466a82c:  callq  0x10466e1a4               ; symbol stub for: objc_retain
0x10466a831:  movq   -0x20(%rbp), %rdi
0x10466a835:  movq   -0x10(%rbp), %rsi
0x10466a839:  movq   %rax, -0x30(%rbp)
0x10466a83d:  callq  0x10466a0e0               ;     LemonadeStand.ViewController.simulateTheDay (LemonadeStand.ViewController)(ObjectiveC.UIButton) -> () at ViewController.swift:65
0x10466a842:  addq   $0x30, %rsp
0x10466a846:  popq   %rbp
0x10466a847:  retq   

编辑:添加了我按钮的属性

<< img src =“ https://image.soinside.com/eyJ1cmwiOiAiaHR0cHM6Ly9pLnN0YWNrLmltZ3VyLmNvbS9xTk1IYy5wbmcifQ==” alt =“开始日按钮代码”>

ios cocoa-touch swift
1个回答
0
投票

您在这里具有正确的属性吗?

enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.