2016-03-14 126 views
0

我一直在這裏工作大約一個小時。我在這個視線中看到了其他問題,並且嘗試了相同的錯誤,並嘗試瞭解決方案。雖然我仍然收到錯誤。這裏是我的代碼:類沒有初始化器?

class Links: UIViewController { 

let firstLinkButton: UIButton? 

let secondLinkButton: UIButton? 


@IBAction func firstLinkButton(sender: AnyObject) { 

    UIApplication.sharedApplication().openURL(NSURL(string: "http://www.google.com")!) 

} 

@IBAction func secondLinkButton(sender: AnyObject) { 

    UIApplication.sharedApplication().openURL(NSURL(string: "http://www.bing.com")!) 



} 


override func viewDidLoad() { 
    super.viewDidLoad() 

    // Do any additional setup after loading the view. 
} 

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

} 

這可能是對這個景象,但今天最簡單的問題,任何輸入或建議,不勝感激。提前致謝。

P.S .: R.I.P.我的聲譽。

+0

究竟是什麼問題? –

+0

我收到一個錯誤「Class Link has no initializers」。 – Bigfoot11

回答

4

使按鈕var

var firstLinkButton: UIButton? 

var secondLinkButton: UIButton? 

let常量必須立即被初始化。

+0

哇!謝謝。這解決了問題。 – Bigfoot11

+0

你也可能希望它們是'@ IBAction',因爲它似乎可能是從nib/storyboard引用的。 –