嘿所以我是新來的編碼,我在我的視圖控制器(拖放)上放置一個按鈕。該按鈕沒有響應觸摸或任何內容,並顯示爲「靜態」。我累了,精疲力竭。有人幫忙?非常感謝!斯威夫特:按鈕沒有響應輕按
import UIKit
class ViewController: UIViewController {
@IBOutlet weak var lbl1: UILabel!
@IBOutlet weak var lblMadeToday: UILabel!
@IBOutlet weak var Cents: UILabel!
var timer = NSTimer()
var hourlyWage : CGFloat = CGFloat (hourlyPrice)
var timeTo1 : CGFloat = 0
var time : Float = 0
var earnt : CGFloat = 0
var madeToday : CGFloat = 0
@IBAction func btnClick(sender: AnyObject) {
}
func tick() {
earnt = CGFloat (time)/timeTo1
lbl1.text = NSString(format: "%.2f", earnt) as String
if (earnt >= 1) {
time = 0
madeToday++
lblMadeToday.text = madeToday.description
}
time++
}
override func viewDidLoad() {
super.viewDidLoad()
timer = NSTimer.scheduledTimerWithTimeInterval(0.01, target: self, selector: Selector("tick"), userInfo: nil, repeats: true)
timeTo1 = CGFloat (360000)/hourlyWage;
println("view Loaded :)")
NSNotificationCenter.defaultCenter().addObserver(self, selector:"doYourStuff", name:
UIApplicationWillEnterForegroundNotification, object: nil)
}
func doYourStuff(){
var nowHour = NSCalendar.currentCalendar().component(.CalendarUnitHour, fromDate: NSDate())
var nowMinute = NSCalendar.currentCalendar().component(.CalendarUnitMinute, fromDate: NSDate())
var nowSecond = NSCalendar.currentCalendar().component(.CalendarUnitSecond, fromDate: NSDate())
var time1 = (nowHour - globalHour) * 60
var time2 = (nowMinute - globalMinute)
var time3 : CGFloat = (CGFloat(nowSecond)-CGFloat(globalSecond))/60
var timeInMinutesGone : CGFloat = CGFloat(time1) + CGFloat(time2) + CGFloat(time3)
println (timeInMinutesGone)
madeToday = (timeInMinutesGone/60) * (CGFloat(hourlyWage))
var ef : Int = Int(madeToday)
lblMadeToday.text = String(ef)
}
@IBAction func btnPress(sender: AnyObject) {
println("hello")
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
IBAction爲FUNC btnPress,IBAction爲FUNC btnClick。爲什麼你有兩個ibactions?他們鏈接到相同的UIButton? – agy
刪除所有IBAction Funcs後,我重新運行應用程序,並且該按鈕仍然不會突出顯示:/是否存在阻止視圖控制器操作的內容?或者是否有定時器引起的處理過載? :/ –
嘗試在IBAction函數中放置打印語句。單擊時查看它是否在控制檯中。 – rholmes