1
var lastnumber: String = ""
@IBOutlet var anserField : UILabel                           Thread 1: breakpoint 2.4
@IBOutlet var operatorLable: UILabel
override func viewDidLoad() {
    super.viewDidLoad()
    // Do any additional setup after loading the view, typically from a nib.
}

override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
    // Dispose of any resources that can be recreated.
}

@IBAction func buttonTapped(TheButton: UIButton) {
    if anserField.text == "0" {
        anserField.text = TheButton.titleLabel.text
    } else {
    anserField.text = anserField.text + TheButton.titleLabel.text
    }
    println(TheButton.titleLabel.text);
}

@IBAction func plusTapped(TheButton: UIButton) {
 println("plus tapped")
    if operatorLable.text == "" {
        operatorLable.text = "+"
        lastnumber = anserField.text
        anserField.text = "0"
    }else {
        enterTapped(nil)
        operatorLable.text = "+"
    }
}

@IBAction func minusTapped(TheButton: UIButton) {
    println("minus tapped")
    if operatorLable.text == "" {
        operatorLable.text = "-"
        lastnumber = anserField.text
        anserField.text = "0"
    }else {
    enterTapped(nil)
        operatorLable.text = "-"
    }
}
@IBAction func cleartapped(AnyObject) {
anserField.text = "0"
    operatorLable.text = ""
    lastnumber = ""
 }

@IBAction func enterTapped(AnyObject?) {
    var num1 = lastnumber.toInt()
    var num2 = anserField.text.toInt()
    if !num1 || !num2 {
    ShowError()
        return
    }
    var anser = 0
    if operatorLable.text == "-" {
   anser = num1! - num2!
    } else if operatorLable.text == "+" {
       anser = num1! + num2!
    } else {
ShowError()
return

    }
    println(anser)
}
func ShowError(){
// to do this
    println("there was a error")
}

}

我需要帮助,我是新手swift和编码,老实说我不是上帝,我无法弄清楚我的代码不会有什么,请帮忙!(错误在顶部,请看右边)我正在编写一个计算器(不知道这是否有帮助,但为什么没有)这是一个我无法修复的错误我尝试了很多东西但没有一个正在工作,它是一个单一视图应用程序,iPhone 5s此代码来自viewcontroler. swift这是解码器和自我的东西,如果它们有用的话

aDecoder    Swift.ImplicitlyUnwrappedOptional<Foundation.NSCoder>   0x00007f829b04fe00  0x00007f829b04fe00
Some    UINibDecoder *  0x00007f829b04fe00  0x00007f829b04fe00
[0] UINibDecoder        
self    calculater.ViewController   0x00007f829a58a980  0x00007f829a58a980
UIKit.UIViewController  UIKit.UIViewController      
UIKit.UIResponder   UIKit.UIResponder       
ObjectiveC.NSObject ObjectiveC.NSObject     
lastnumber  Swift.String    unable to read data 
core    Swift._StringCore       
_baseAddress    Swift.COpaquePointer    0x00000001078bd538  0x00000001078bd538 calculater.__TEXT.__ustring + 40
value   Builtin.RawPointer  0x1078bd538 0x00000001078bd538 calculater.__TEXT.__ustring + 40
_countAndFlags  Swift.UWord 9223372036854775808 -9223372036854775808
value   Builtin.Word    -9223372036854775808    -9223372036854775808
_owner  Swift.Optional<AnyObject>   nil None
anserField  @sil_weak Swift.ImplicitlyUnwrappedOptional<UIKit.UILabel>      
Some    UIKit.UILabel       
UIKit.UIView    UIKit.UIView        
UIKit.UIResponder   UIKit.UIResponder       
ObjectiveC.NSObject ObjectiveC.NSObject     
operatorLable   @sil_weak Swift.ImplicitlyUnwrappedOptional<UIKit.UILabel>      
Some    UIKit.UILabel       
UIKit.UIView    UIKit.UIView        
UIKit.UIResponder   UIKit.UIResponder       
ObjectiveC.NSObject ObjectiveC.NSObject 

如果您需要其他任何东西来解决问题,请发表评论

这就是我关闭断点并按下某些按钮时发生的事情(更多信息见评论)

2014-08-22 23:39:05.613 计算器 [6307:2641435] - [_TtC10calculator14ViewController plusTapped:]:无法识别的选择器发送到实例 0x7faad9dbd150 2014-08-22 23:39:05.617 计算器 [6307:2641435] * 终止应用程序uncaught exception 'NSInvalidArgumentException', reason: '-[_TtC10calculater14ViewController plusTapped:]: unrecognized selector sent to instance 0x7faad9dbd150' * First throw call stack: ( 0 CoreFoundation 0x00000001070f5055 exceptionPreprocess + 165 1 libobjc.A.dylib 0x0000000108bafa1c objc_exception_throw + 45 2 CoreFoundation 0x00000001070fbf1d - [NSObject(NSObject) doesNotRecognizeSelector:] + 205 3 CoreFoundation 0x0000000107054dbc ___forwarding_+ 988 4 CoreFoundation 0x0000000107054958 _CF_forwarding_prep_0 + 120 5 UIKit 0x0000000107974196 -[UIApplication sendAction:to:from:forEvent:] + 75 6 UIKit 0x0000000107a78c80 -[UIControl _sendActionsForEvents:withEvent:] + 467 7 UIKit 0x0000000107a7804f -[UIControl touchesEnded:withEvent:] + 522 8 UIKit 0x00000001079b9368 -[UIWindow _sendTouchesForEvent:] + 735 9 UIKit 0x00000001079b9c93 -[UIWindow sendEvent:] + 683 10 UIKit 0x0000000107986f51 -[UIApplication sendEvent:] + 246 11 UIKit 0x0000000107993ec6 _UIApplicationHandleEventFromQueueEvent + 17699 12 UIKit 0x000000010796fcd9 _UIApplicationHandleEventQueue + 1967 13 CoreFoundation 0x000000010702b0b1CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION + 17 14 CoreFoundation 0x000000010702099d __CFRunLoopDoSources0 + 269 15 CoreFoundation 0x000000010701ffd4 __CFRunLoopRun + 868 16 CoreFoundation 0x000000010701fa06 CFRunLoopRunSpecific + 470 17 GraphicsServices 0x000000010adbeabf GSEventRunModal + 161 18 UIKit 0x0000000107972cf8 UIApplicationMain + 1282 19 calculater 0x0000000106c7f6ed top_level_code + 77 20 calculater 0x0000000106c7f72a main + 42 21 libdyld.dylib 0x0000000109120145 start + 1 ) libc++abi.dylib: 以 NSException (lldb) 类型的未捕获异常终止

4

0 回答 0