【发布时间】:2014-10-19 03:51:35
【问题描述】:
在过去的三个小时里,这一直困扰着我,我似乎无法理解它。
我有以下 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 模拟器中的所有设置和数据。似乎没有任何效果。
如果有用的话,这里是以前的堆栈跟踪。
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
编辑:添加了我的按钮属性
【问题讨论】:
-
你能添加你的按钮属性吗?
-
我修改了问题以添加按钮的连接属性。
-
只是预感。将 showAlertMessage 的名称更改为其他名称,例如 myShowAlertMessage
-
不。仍然在同一个地方崩溃..这真的让我很紧张..这是我遇到过的最奇怪的事情。
标签: ios cocoa-touch swift