我有一个Objective-c类(RDAlertView)
,它创建一个Alert(UIAlertView for ios< 8和UIAlertController for ios> = 8)
以下是Objective-C中的代码:
RDAlertView* alert = [[RDAlertView alloc] initWithTitle:@"Notification"
message:@"message"
completion:completion:^(NSInteger buttonIndex, NSInteger cancelButtonIndex, NSArray *textflieds) { }
cancelButtonTitle:@"Ok"
otherButtonTitles:nil];
[alert show];
我的问题是:如何在我的课程中没有任何变化(如果可能的话)在Swift中调用它?
以下是示例项目的链接:https://bitbucket.org/ejanowski/rdalertview-issue
答案 0 :(得分:2)
我认为这就是你所需要的:
var alert = RDAlertView(title: "Notification", message: "message", completion: nil, cancelButtonTitle: "OK", otherButtonTitles: nil)
alert.show()
希望它会有所帮助。
答案 1 :(得分:1)
这些方法被视为构造函数。你可以像这样打电话给他们:
var alert = RDAlertView("notification", message:"message", completion:nil, cancelButtonTitle:"Cancel", otherButtonTitles:nil)
alert.show()
警告:没有IDE编写,小心语法错误/拼写错误
答案 2 :(得分:1)
UIAlertView
。
您可以使用以下代码显示提醒:
var alert = UIAlertController(title: "Alert", message: "test", preferredStyle: UIAlertControllerStyle.Alert)
alert.addAction(UIAlertAction(title: "Click", style: UIAlertActionStyle.Default, handler: nil))
self.presentViewController(alert, animated: true, completion: nil)
答案 3 :(得分:0)
UIAlertView.showWithTitle("Hello", message: "Hello World", cancelButtonTitle: "Okay") { alertView, buttonIndex in
// Do something when the alert view is clicked
let anAlertView = UIAlertView(title: "Choice", message: "Pick one", cancelButtonTitle: "No", otherButtonTitles: "Yes", "Maybe")
anAlertView.showWithCompletion { alertView, buttonIndex in
switch buttonIndex
{
case 1: println("Yes")
case 2: println("Maybe")
default: println("No")
}
}