我正在製作一個應用程序,每次我搖動我的手機時都會從我的陣列中選擇一個隨機問題。如下所示;我試圖在「覆蓋函數motionBegan」中調用「print」函數,但它不起作用。任何人都可以幫忙。?從視圖控制器訪問變量覆蓋函數
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
let array = ["what did your eat for breakfast?", "First time you kissed a boy/girl? Explain.", "Whats your body count?", "When was the last time you went to church?", "Would you date someone from another religion?", "East booty(Guy) ?or let a guy eat your booty(Girl)?", "If you die right now where will you end?", "whats on your mind?", "Ever has a one night stand?", "Do you find the other person attractive?", "How old where you when you first hd sex?. Explain.", "You believe in Jesus?", "Where do you see yourself in 10 years?", "First time you gave head?", "Slap your mum or your dad? Choose one.", "Last time you watched porn?", "How much is in your account?", "One thing you hate about the other person?", "One thing you love about the other person?", "Would you kiss the person close to you?", "One thing you hate about yourself?", " One thing you love about yourself?","Suck toes or eat booty?", "Best rapper?", "Best singer?", "If you had a billion dollars for 24 hours how will you spend it?"]
let randomIndex = Int(arc4random_uniform(UInt32(array.count)))
// Get a random item
let randomItem = array[randomIndex]
func print() {
textField.text = randomItem
}
}
override func motionBegan(_ motion: UIEventSubtype, with event: UIEvent?) {
print;
}
什麼問題?在執行'motionBegan'函數時你需要'覆蓋'嗎? –
您在Didload中選擇了動態問題,而不是在創建的函數中選擇它,並在檢測到的動作結束時調用新創建的函數,並在didLoad中調用一次,希望它有幫助 –
您確定代碼格式良好嗎?你的方法之前有太多的閉括號? – Maxime