swift selector 按钮点击事件

来源:互联网 发布:域名劫持是什么意思 编辑:程序博客网 时间:2024/06/05 04:18

1、导航栏按钮

UIBarButtonItem(    title: "Some Title",    style: UIBarButtonItemStyle.Done,    target: self,    action: "flatButtonPressed:")
2、普通按钮
flatButton.addTarget(self, action: "flatButtonPressed:", forControlEvents: UIControlEvents.TouchUpInside)
func flatButtonPressed(sender: AnyObject) {  NSLog("flatButtonPressed")}

3、timer
var timer = NSTimer.scheduledTimerWithTimeInterval(1.0,                     target: self,                     selector: Selector("flatButtonPressed"),                     userInfo: userInfo,                     repeats: true)    let mainLoop = NSRunLoop.mainRunLoop()  //1    mainLoop.addTimer(timer, forMode: NSDefaultRunLoopMode) //2 this two line is optinal
func flatButtonPressed(timer: NSTimer) {}

0 0
原创粉丝点击