Swift中Selector变化
2.2 之前,使用字符串作为方法名称
//无参数
btn.addTarget(self, action: Selector("buttonPress") , forControlEvents: .TouchUpInside) //有参数
btn.addTarget(self, action: Selector("buttonPress:") , forControlEvents: .TouchUpInside)
2.2~3.0期间
//无参数:
btn.addTarget(self, action: #selector(buttonPress), forControlEvents: .TouchUpInside) //有参数(参数的名称使用下划线“_”,实现事件时,参数名称可以任意设置)
btn.addTarget(self, action: #selector(buttonPress(_:)), forControlEvents: .TouchUpInside)
3.0变化
//无参数
btn.addTarget(self, action: #selector(buttonPress), for: .touchUpInside) //有参数(参数的名称必须具体给出,而且实现事件时,参数名称保持一致)
btn.addTarget(self, action: #selector(buttonPress(sender:)), for: .touchUpInside)