所以,我对XCode和Swift很新。我在更改UIButton上的标题文本时遇到问题,并且我一直收到错误
致命错误:在解包可选值时意外发现nil
This is my code :
//
// ViewController.swift
// mtgHealthTracker
//
// Created by Reagan McFarland on 5/1/16.
// Copyright © 2016 Reagan McFarland. All rights reserved.
//
import UIKit
class ViewController: UIViewController {
//Mark : Properties
@IBOutlet weak var btnPlayer1Health: UIButton!
@IBOutlet weak var btnPlayer4Health: UIButton!
@IBOutlet weak var btnPlayer3Health: UIButton!
@IBOutlet weak var btnPlayer2Health: UIButton!
@IBOutlet weak var lblCurrWinner: 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.
}
//Mark Actions
@IBAction func btnPlayer1HealthChanged(sender: UIButton, forEvent event: UIEvent) {
btnPlayer1Health.setTitle("Hello World", forState: UIControlState.Normal)
}
@IBAction func btnPlayer2HealthChanged(sender: UIButton, forEvent event: UIEvent) {
}
非常感谢帮助!谢谢:))
答案 0 :(得分:1)
您的一个或多个IBOutlet未在您的XIB / Storyboard中连接。确保选择文件所有者并将IBOutlet拖到XIB / Storyboard元素中。