SCLAlertView 未显示

SCLAlertView not showing

我在 objective c 中实现了 SCLAlertView。现在我们将项目移植到 swift。我在桥接头文件中添加了 SCLAlertView.h。没问题。

我写的这段代码没有任何错误,但是当我执行代码时它没有显示警报。

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(正如您提到的)版本的 SCLAlertView 并桥接它,应该是 -as an Objective c-:

[alert showError:self title:@"Hello Error" subTitle:@"This is a more descriptive error text." closeButtonTitle:@"OK" duration:0.0f]; // Error

如你所见,第一个参数self指的是你想让alert出现在其中的当前UIViewController

所以,转换为Swift代码后,应该是:

alert.showError(self, title: "Title", subTitle: "This is a message", closeButtonTitle: "OK", duration: 0.1)

您在代码片段中提到的内容在使用 SCLAlertView 的 Swift 版本时应该可以正常工作。

请注意,它们是不同的回购协议。如果您的项目已构建为 "Swift" 编码,我鼓励使用 Swift 版本的 SCLAlertView,您不必 "bridge" 它。