首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >WatchKit和UIAlertView / UIAlertController弹出窗口

WatchKit和UIAlertView / UIAlertController弹出窗口
EN

Stack Overflow用户
提问于 2015-03-18 00:51:09
回答 7查看 11.9K关注 0票数 19

在我的WatchKit应用程序中,当用户第一次启动它时,我想向他们展示一个有用的消息提醒,告诉他们应用程序是如何工作的,例如按钮是做什么的等等。

有没有类似于UIAlertView / UIAlertController的东西可以在WatchKit应用中调用?我在这个话题上找不到答案,这很可能意味着这是不可能的。

EN

回答 7

Stack Overflow用户

回答已采纳

发布于 2015-07-02 14:06:33

( watchOS 2.0中的新功能)

代码语言:javascript
复制
 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];

斯威夫特

代码语言:javascript
复制
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])

}
票数 58
EN

Stack Overflow用户

发布于 2017-10-30 18:04:08

我将添加适用于我的swift4结果,同时使用

WKAlertAction

watchOS 4.0

Swift 4

代码语言:javascript
复制
        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])
票数 12
EN

Stack Overflow用户

发布于 2015-06-18 20:51:48

可以,升级到watchOS 2后,您可以使用WKInterfaceController的presentAlertController显示警报视图。

参见the official documentation here

票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/29105027

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档