Objective c SCLARTERVIEW未显示
我在目标c中实现了SCLAlertView。现在我们将项目移植到swift。我已在桥接头文件中添加了SCLAlertView.h。没问题 我已经编写了这段代码,它没有任何错误,但在执行代码时不会显示警报Objective c SCLARTERVIEW未显示,objective-c,swift,alert,Objective C,Swift,Alert,我在目标c中实现了SCLAlertView。现在我们将项目移植到swift。我已在桥接头文件中添加了SCLAlertView.h。没问题 我已经编写了这段代码,它没有任何错误,但在执行代码时不会显示警报 let alert = SCLAlertView() alert.showError("Title", subTitle: "This is a message", closeButtonTitle: "OK", duration: 0.1) 替换此 alert.showError("Tit
let alert = SCLAlertView()
alert.showError("Title", subTitle: "This is a message", closeButtonTitle: "OK", duration: 0.1)
替换此
alert.showError("Title", subTitle: "This is a message", closeButtonTitle: "OK", duration: 0.1)
与
alert.showSuccess(self, title: "Title", subTitle:"This is a message", closeButtonTitle: "OK", duration: 0.1)
为什么您的代码不能正常工作的奥秘在于:
您正在使用的是的Objective c(正如您所提到的)版本并将其连接起来,作为Objective c,它应该:
[alert showError:self title:@"Hello Error" subTitle:@"This is a more descriptive error text." closeButtonTitle:@"OK" duration:0.0f]; // Error
如您所见,第一个参数self
指的是要让警报显示在其中的当前UIViewController
因此,将其转换为Swift代码后,应为:
alert.showError(self, title: "Title", subTitle: "This is a message", closeButtonTitle: "OK", duration: 0.1)
您在代码片段中提到的内容在使用Swift版本的时应该可以正常工作
请注意,它们是不同的回购协议。如果您的项目是按照“Swift”编码构建的,我鼓励您使用Swift版本的SCALlertView,您不必“桥接”它。酷。谢谢注意。!!很高兴为您提供帮助:)您似乎是stackoverflow的新用户,我想告诉您,对问题/答案投赞成票/反对票并接受它们是很好的,这会引起其他观众的注意,也有助于回答者提高他们的声誉,如果答案是错误的,他们会减少回答。您可能需要检查权限。振作起来