【问题标题】:Hyperlink button always open google.com超链接按钮始终打开 google.com
【发布时间】:2017-07-08 06:49:11
【问题描述】:

我做了一个打开链接的操作,但是当我按下它时,它总是打开 google.com(模拟器和真手机)。 仅仅是因为它是从 xcode 或其他东西启动的吗? 这是代码

@IBAction func linkPremium(sender: AnyObject) {
    UIApplication.shared.openURL(NSURL(string:"http://www.apple.com") as! URL)
}


func createMenu() {
    let menuWidth: CGFloat = self.view.frame.width/2
    let menuHeight: CGFloat = self.view.frame.height


    let ee = UIButton (frame: CGRect(x:0,y:280, width: menuWidth,height: 60.0))
    ee.setTitle("Premium", for: .normal)
    ee.setTitleColor(UIColor.black, for: .normal)

    ee.addTarget(self, action: #selector(linkPremium(sender:)), for: .touchUpInside)
    menuView.addSubview(ee)
    view.addSubview(menuView)
}



override func viewDidLoad() {
    super.viewDidLoad()

    createMenu()
}

【问题讨论】:

    标签: swift url button hyperlink action


    【解决方案1】:

    当我在模拟器中运行这一行时

    UIApplication.shared.openURL(NSURL(string:"http://www.apple.com") as! URL)
    

    它会打开 apple.com

    检查您的 closeMenu 函数,看看您是否在那里进行任何更改

    【讨论】:

    • 我的错,我不调用 closeMenu 方法而是调用 linkPremium 方法
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-09-25
    • 2015-12-19
    • 2021-11-22
    • 2019-01-11
    • 1970-01-01
    • 2017-03-29
    相关资源
    最近更新 更多