Swift的新功能 - 我試圖在預定義的時間失效後實現簡單的繼續操作。但由於某種原因,我的xcode不識別Timer
,並給出錯誤「定時器模塊沒有名爲scheduledTimer的成員」。我無法在任何地方找到幫助。XCode無法識別Timer() - Swift 3
CODE:
import UIKit
class ViewController: UIViewController {
let emptystring = String()
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
var time = Timer.scheduledTimer(timeInterval: 8.0, target: self, selector: #selector(changeview), userInfo: nil, repeats: false)
}
func changeview(){
self.performSegueWithIdentifier("GoToMain", sender: self)
}
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
if (segue.identifier == "GoToMain"){
let destination = (segue.destinationViewController as! UINavigationController).viewControllers[0] as! SecondView
destination.emptyString = emptystring
}
print("Segue Performed")
}
}
Picture也顯示了我的整個代碼,包括錯誤。注意:這不是我自己的代碼。我只跟着回答問題,在下面的鏈接:
Xcode Swift 3: Timer and Segue View Controller Error
即使使用NSTimer,它也會重複出現相同的錯誤。 p.s:我對這個愚蠢的錯誤非常抱歉 –
@ZairaZafar在上面的修訂答案中參見Swift 2和Swift 3的翻譯。請注意,如果您在切割和粘貼未來堆棧溢出時發現的代碼時遇到麻煩,請註釋掉粘貼的代碼,並嘗試自己輸入代碼並依靠「代碼補全」來獲得正確的語法,標籤等。 – Rob
謝謝非常!這有幫助! –