我的应用是简单的应用程序崩溃

时间:2016-10-29 23:11:09

标签: ios xcode crash swift3 xcode8

我制作了一个小程序,用来计算工作中保险箱的钱。但在更新我的iPhone后它崩溃了。我已经尝试了很多,但找不到解决方案。

当我按下激活以下功能的按钮时发生崩溃:

@IBAction func Knap(sender: AnyObject) {}

我对编码很新,所以请尽量保持答案:)

我的应用程序如下:

//
//  ViewController.swift
//  Pengeskabstæller
//
//  Created by Alex on 09/07/2016.
//  Copyright © 2016 Alex. All rights reserved.
//

import UIKit


class ViewController: UIViewController, UITextFieldDelegate {

@IBOutlet weak var In50B: UITextField!
@IBOutlet weak var In50L: UITextField!
@IBOutlet weak var In20B: UITextField!
@IBOutlet weak var In20L: UITextField!
@IBOutlet weak var In10B: UITextField!
@IBOutlet weak var In10L: UITextField!
@IBOutlet weak var In5B: UITextField!
@IBOutlet weak var In5L: UITextField!
@IBOutlet weak var In2B: UITextField!
@IBOutlet weak var In2L: UITextField!
@IBOutlet weak var In1B: UITextField!
@IBOutlet weak var In1L: UITextField!
@IBOutlet weak var In05B: UITextField!
@IBOutlet weak var In05L: UITextField!
@IBOutlet weak var Ialt: 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.
}

override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
    view.endEditing(true)
}

@IBAction func Knap(sender: AnyObject) {
    //Hvad knappen gør

    //Ganger input ved værdi af bundt eller løse
    var x50B: Int = Int(In50B.text!)!
    x50B = x50B*5000
    var x50L:Int = Int(In50L.text!)!
    x50L = x50L*500
    var x20B:Int = Int(In20B.text!)!
    x20B = x20B*4000
    var x20L:Int = Int(In20L.text!)!
    x20L = x20L*400
    var x10B:Int = Int(In10B.text!)!
    x10B = x10B*2000
    var x10L:Int = Int(In10L.text!)!
    x10L = x10L*200
    var x5B:Int = Int(In5B.text!)!
    x5B = x5B*1000
    var x5L:Int = Int(In5L.text!)!
    x5L = x5L*200
    var x2B:Int = Int(In2B.text!)!
    x2B = x2B*500
    var x2L:Int = Int(In2L.text!)!
    x2L = x2L*50
    var x1B:Int = Int(In1B.text!)!
    x1B = x1B*500
    var x1L:Int = Int(In1L.text!)!
    x1L = x1L*50
    var x05B:Int = Int(In05B.text!)!
    x05B = x05B*200
    var x05L:Int = Int(In05L.text!)!
    x05L = x05L*20

    //Lægger det hele sammen

    let penge1 = (x50B + x50L + x20B)
    let penge2 = (x20L + x10B + x10L)
    let penge3 = (x5B + x5L + x2B + x2L)
    let penge4 = (x1B + x1L + x05B + x05L)
    let penge99 = String(penge1+penge2+penge3+penge4)

    //Printer ialt
    Ialt.text = penge99
}

}

崩溃说明是:

2016-10-30 01:13:57.687826 Pengeskabstæller[879:222437] -[Pengeskabstæller.ViewController Knap:]: unrecognized selector sent to instance 0x13fe0aac0
2016-10-30 01:13:57.688704 Pengeskabstæller[879:222437] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[Pengeskabstæller.ViewController Knap:]: unrecognized selector sent to instance 0x13fe0aac0'
*** First throw call stack:
(0x1858641c0 0x18429c55c 0x18586b278 0x185868278 0x18576259c 0x18b6e19a0 0x18b6e1920 0x18b6cbdd0 0x18b6e120c 0x18b6e0d34 0x18b6dbf7c 0x18b6aca44 0x18be99ea8 0x18be93910 0x185812278 0x185811bc0 0x18580f7c0 0x18573e048 0x1871c1198 0x18b717818 0x18b712550 0x1000e9368 0x1847205b8)
libc++abi.dylib: terminating with uncaught exception of type NSException

1 个答案:

答案 0 :(得分:1)

替换它:

@IBAction func Knap(sender: AnyObject)

用这个

@IBAction func Knap(_ sender: AnyObject)

由于 Swift 3 ,如果要省略它,则需要在外部参数名称之前添加下划线。最有可能出现问题的原因是您在迁移到 Swift 3 之前添加了IBActions