swift selector 按钮点击事件

前端之家收集整理的这篇文章主要介绍了swift selector 按钮点击事件前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

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,selector: Selector("flatButtonPressed"),userInfo: userInfo,repeats: true)
    let mainLoop = NSRunLoop.mainRunLoop()  //1
    mainLoop.addTimer(timer,forMode: NSDefaultRunLoopMode) //2 this two line is optinalfunc flatButtonPressed(timer: NSTimer) {
} 原文链接:https://www.f2er.com/swift/325949.html

猜你在找的Swift相关文章