WatchKit 和 UIAlertView / UIAlertController 弹出窗口
WatchKit and UIAlertView / UIAlertController popup
在我的 WatchKit 应用程序中,当用户首次启动它时,我想向他们展示一条有用的消息提醒,告诉他们该应用程序如何工作,例如按钮的作用等等
我可以在 WatchKit 应用程序中调用类似于 UIAlertView / UIAlertController 的东西吗?我找不到关于这个主题的答案,这很可能意味着这是不可能的。
没有这样的 class 警报。但是,您可以使用 "WKInterfaceLabel" 和 "WKInterfaceButton".
中的信息模态呈现 "WKInterfaceController"
遗憾的是,您不能这样做。但是,如果是第一次启动该应用程序,您当然可以拥有一个基于模式页面的层次结构,其中包含该应用程序如何工作的屏幕截图。我正在我的应用程序中这样做! :)
如果我能再提出一个建议:在您的初始界面控制器中为您的 "alert" 创建一个单独的组,并根据需要 show/hide 它。
是的,升级到 watchOS 2 后,您可以使用 WKInterfaceController 的 presentAlertController 呈现警报视图。
(watchOS 2.0 新增功能)
WKAlertAction *act = [WKAlertAction actionWithTitle:@"OK" style:WKAlertActionStyleCancel handler:^(void){
NSLog(@"ALERT YES ");
}];
NSArray *testing = @[act];
[self presentAlertControllerWithTitle:@"Voila" message:@"This is Watch OS 2 !" preferredStyle:WKAlertControllerStyleAlert actions:testing];
SWIFT
func showPopup(){
let h0 = { print("ok")}
let action1 = WKAlertAction(title: "Approve", style: .default, handler:h0)
let action2 = WKAlertAction(title: "Decline", style: .destructive) {}
let action3 = WKAlertAction(title: "Cancel", style: .cancel) {}
presentAlert(withTitle: "Voila", message: "", preferredStyle: .actionSheet, actions: [action1,action2,action3])
}
let h0 = { print("h0 action")}
let h1 = { print("h1 action")}
let action1 = WKAlertAction(title: "h0 action", style: .default, handler:h0)
let action2 = WKAlertAction(title: "h1 action", style: .default, handler:h0)
self.presentAlert(withTitle: "Title", message: "a message", preferredStyle: .actionSheet, actions: [action1, action2])
代码在Swift3
我将在使用时添加对我有用的 swift4 结果
WKAlertAction
watchOS 4.0
Swift 4
let action1 = WKAlertAction.init(title: "Cancel", style:.cancel) {
print("cancel action")
}
let action2 = WKAlertAction.init(title: "default", style:.default) {
print("default action")
}
let action3 = WKAlertAction.init(title: "destructive", style:.destructive) {
print("destructive action")
}
presentAlert(withTitle: "Alert Title", message: "message is here", preferredStyle:.actionSheet, actions: [action1,action2,action3])
在我的 WatchKit 应用程序中,当用户首次启动它时,我想向他们展示一条有用的消息提醒,告诉他们该应用程序如何工作,例如按钮的作用等等
我可以在 WatchKit 应用程序中调用类似于 UIAlertView / UIAlertController 的东西吗?我找不到关于这个主题的答案,这很可能意味着这是不可能的。
没有这样的 class 警报。但是,您可以使用 "WKInterfaceLabel" 和 "WKInterfaceButton".
中的信息模态呈现 "WKInterfaceController"遗憾的是,您不能这样做。但是,如果是第一次启动该应用程序,您当然可以拥有一个基于模式页面的层次结构,其中包含该应用程序如何工作的屏幕截图。我正在我的应用程序中这样做! :)
如果我能再提出一个建议:在您的初始界面控制器中为您的 "alert" 创建一个单独的组,并根据需要 show/hide 它。
是的,升级到 watchOS 2 后,您可以使用 WKInterfaceController 的 presentAlertController 呈现警报视图。
(watchOS 2.0 新增功能)
WKAlertAction *act = [WKAlertAction actionWithTitle:@"OK" style:WKAlertActionStyleCancel handler:^(void){
NSLog(@"ALERT YES ");
}];
NSArray *testing = @[act];
[self presentAlertControllerWithTitle:@"Voila" message:@"This is Watch OS 2 !" preferredStyle:WKAlertControllerStyleAlert actions:testing];
SWIFT
func showPopup(){
let h0 = { print("ok")}
let action1 = WKAlertAction(title: "Approve", style: .default, handler:h0)
let action2 = WKAlertAction(title: "Decline", style: .destructive) {}
let action3 = WKAlertAction(title: "Cancel", style: .cancel) {}
presentAlert(withTitle: "Voila", message: "", preferredStyle: .actionSheet, actions: [action1,action2,action3])
}
let h0 = { print("h0 action")}
let h1 = { print("h1 action")}
let action1 = WKAlertAction(title: "h0 action", style: .default, handler:h0)
let action2 = WKAlertAction(title: "h1 action", style: .default, handler:h0)
self.presentAlert(withTitle: "Title", message: "a message", preferredStyle: .actionSheet, actions: [action1, action2])
代码在Swift3
我将在使用时添加对我有用的 swift4 结果
WKAlertAction
watchOS 4.0
Swift 4
let action1 = WKAlertAction.init(title: "Cancel", style:.cancel) {
print("cancel action")
}
let action2 = WKAlertAction.init(title: "default", style:.default) {
print("default action")
}
let action3 = WKAlertAction.init(title: "destructive", style:.destructive) {
print("destructive action")
}
presentAlert(withTitle: "Alert Title", message: "message is here", preferredStyle:.actionSheet, actions: [action1,action2,action3])