2016-11-04 122 views
-1

所以定时器只工作一次,但在第一次后它不再工作了......这是什么问题,它如何被修复?谢谢!定时器只执行一次函数

override func viewDidLoad() { 
     super.viewDidLoad() 

let myTimer : Timer = Timer.scheduledTimer(timeInterval: 7, target: self, selector: (selector: "functionOne"), userInfo: nil, repeats: true) 
     } 
    } 
    func functionOne() 
    { 
     print("hello") 

    } 
+1

仅供参考 - 你的斯威夫特3选择语法不正确。请参阅http://stackoverflow.com/questions/24007650/selector-in-swift – rmaddy

回答

1

试试这个代码:

override func viewDidLoad() { 
    super.viewDidLoad() 
    // Do any additional setup after loading the view, typically from a nib. 

    Timer.scheduledTimer(timeInterval: 7.0, target: self, selector: #selector(functionOne), userInfo: nil, repeats: true) 

} 

func functionOne() { 
    print("hello") 
} 

输出:

enter image description here