ios - Swift 每次内存地址跳转都会崩溃

标签 ios cocoa-touch swift

在过去的三个小时里,这一直困扰着我,我似乎并没有完全理解它。

我有以下 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()
}

任何地方的自我。是我类的一个全局变量。
每当我单击与此 socket 相关的按钮时,应用程序就会崩溃并在顶部突出显示我的 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 并重新创建它,尝试在我的 Storyboard中创建一个新的 UIButton,并将其链接到一个新的 IBOutlet,尝试清理项目,尝试清除 iOS 模拟器上的所有设置和数据。似乎没有任何效果。

这是以前的堆栈跟踪,如果它有帮助的话。
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   

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

Start Day Button Code

最佳答案

你在这里有正确的属性吗?

enter image description here

关于ios - Swift 每次内存地址跳转都会崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26447108/

相关文章:

ios - 当键盘出现时向上移动文本字段会留下黑条

ios - MKMapView:自定义 View 代替 Annotation Pin

ios - NSAttributedString:不应用下划线

iOS 将照片保存到相机胶卷不会保留 EXIF/GPS 元数据

iphone - iPhone 应用程序中的数据持久性

iphone - 如何在重置之前更新密码标签?

ios - Stripe Radar 规则不适用于 Apple Pay 待授权

ios - 如果用户使用的是 iOS 3.1.3 或更低版本,则导入 iOS 3.2 源代码

ios - 为什么我在执行 selector :withObject:@YES in iOS, 时总是得到 NO,这在 macOS 中是不同的?

ios - 密集的数据处理使UI交互无法生效