【问题标题】:blank screen appears when click on UILabel in swift在swift中单击UILabel时出现空白屏幕
【发布时间】:2015-10-10 03:23:39
【问题描述】:

当点击 UIlabel 时,我正在尝试使用所选号码打开 iPhone 通话屏幕,UIlabel 是 swift 中的超链接。

一个空白屏幕出现 1 秒钟然后消失。没有出现 iPhone 通话屏幕。不知道我的代码有什么问题。

viewDidLoad 中的代码

let strPhone = "080 2854 2105"

let attributedPhoneStr = NSMutableAttributedString(string:strPhone, attributes:[NSLinkAttributeName: NSURL(string: "http://aerospace.honeywell.com")!])

lblPhoneContact.attributedText = attributedPhoneStr

lblPhoneContact.userInteractionEnabled = true

let gestureRecognizer = UITapGestureRecognizer(target: self, action: Selector("labelPressed"))

lblPhoneContact.addGestureRecognizer(gestureRecognizer)

函数标签按下

func labelPressed() {      

let url:NSURL = NSURL(string: "tel://08028542105")!

UIApplication.sharedApplication().openURL(url)

}

我的代码有什么问题或缺失。 我尝试在我的 iPhone 设备上运行。

【问题讨论】:

    标签: ios iphone swift uilabel


    【解决方案1】:

    快速使用

    let url:NSURL = NSURL(string: "telprompt:08028542105")!
    

    而不是

    let url:NSURL = NSURL(string: "tel://08028542105")!
    

    【讨论】:

    • 没有。使用“telprompt://”将调用请求呼叫,但使用“tel://”将直接呼叫号码,无需提示请求。
    【解决方案2】:

    您可以尝试使用 GCD 的 dispatch_async 来调用“openURL”方法:

    dispatch_async(dispatch_get_main_queue()) { () -> Void in
        UIApplication.sharedApplication().openURL(url)
    }
    

    【讨论】:

      【解决方案3】:

      你应该省略 uri 中的 // - 即它应该只是

      let url:NSURL = NSURL(string: "tel:08028542105")!
      

      【讨论】:

        猜你喜欢
        • 2015-06-21
        • 2023-04-04
        • 2020-06-23
        • 1970-01-01
        • 1970-01-01
        • 2020-01-30
        • 1970-01-01
        • 1970-01-01
        • 2020-03-05
        相关资源
        最近更新 更多