2017-03-10 46 views
-1

我正在使用Swift游乐场试图制作一个交互式应用程序,用户可以在其中单击按钮执行操作。Swift Playgrounds - 使用未解析的标识符'self'

let tapGesture = UITapGestureRecognizer(target: self, action: #selector(self.tapBlurButton(_:))) 

func tapBlurButton(_ sender: UITapGestureRecognizer) { 
print("Please Help!") 
} 

这是给我的错误:

'use of unresolved identifier self'

。 我如何在Swift 3中修复这个问题?

回答

0

该代码不会工作,除非它在从NSObject继承的类中。

如果是在班级中,而且您仍然收到该错误,则可能是因为tapGesture是属性。在初始化过程中,属性通常不能使用self

0

FUNC tapBlurButton前加上@objc ...

相关问题