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、timervar 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