在我的WatchKit应用程序中,当用户第一次启动它时,我想向他们展示一个有用的消息提醒,告诉他们应用程序是如何工作的,例如按钮是做什么的等等。
有没有类似于UIAlertView / UIAlertController的东西可以在WatchKit应用中调用?我在这个话题上找不到答案,这很可能意味着这是不可能的。
发布于 2015-07-02 14:06:33
( 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];
斯威夫特
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])
}
发布于 2017-10-30 18:04:08
我将添加适用于我的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])
发布于 2015-06-18 20:51:48
可以,升级到watchOS 2后,您可以使用WKInterfaceController的presentAlertController显示警报视图。
https://stackoverflow.com/questions/29105027
复制相似问题