无法识别的选择器发送到实例swift

时间:2015-02-20 01:59:17

标签: ios xcode swift

我写了我认为简单的小程序。代码中没有错误标志,它编译得很好。但是,当我单击模拟器中的按钮时,程序将以"无法识别的选择器发送到实例"

中止

以下是完整代码:

//
//  ViewController.swift
//  Boys and girls
//
//  Created by Michael Wilson on 2/20/15.
//  Copyright (c) 2015 Mind Wiz Labs. All rights reserved.
//

import UIKit

class ViewController: UIViewController {

    @IBOutlet weak var boystotal: UILabel!

    @IBOutlet weak var girlstotal: UILabel!

    @IBOutlet weak var motherstotal: UILabel!
    @IBOutlet weak var reproduceButton: UIButton!


    var boys = 0
    var girls = 0
    var mothers = 1000
    var totalgirls = 0
    var totalboys = 0



    func makeBaby() {
    var randomBaby = arc4random() % 2
    switch(randomBaby){
    case 0:
    boys += 1


    case 1:
    girls += 1

    default: break


        }
    }
    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 reproducePressed(sender: AnyObject) {


    [makeBaby()]

        if girls > 0 {

            mothers -= 1
            totalgirls += 1
            girlstotal.text = String(totalgirls)
            girls = 0
            motherstotal.text = String(mothers)


        } else {

            if boys > 0 {
                totalboys += 1
                boystotal.text = String(totalboys)
                boys = 0
                motherstotal.text = String(mothers)
            }
        }
    }





}

1 个答案:

答案 0 :(得分:0)

我的不好,这个按钮也挂了一个幻影方法。在连接检查器中删除它,现在它可以正常工作。