条形按钮项目打开多个 URL?

Bar button Item to open multiple URLs?

我最近看到下面的代码。是否可以 link 一个条形按钮项目到多个 URL ?即通过点击按钮,我可以选择我想在运行时去哪个网站?或者我可以只 link 一个栏按钮到一个 URL 吗?

override func  viewDidLoad() {
super.viewDidLoad()
googleButton.addTarget(self, action: "didTapGoogle", forControlEvents: .TouchUpInside)}

@IBAction func didTapGoogle(sender: AnyObject) {
UIApplication.sharedApplication().openURL(NSURL(string:"http://www.google.com")!)}

将其用作侧边栏菜单。

此库将侧边栏菜单置于 viewcontroller 和导航栏之上。

https://github.com/balram3429/BTSimpleSideMenu

在objective c里面,不过你可以桥接使用。 swift 中还有其他侧边栏菜单可用,只需确保它必须在视图控制器和导航栏上打开。

在桥接文件中导入这 2 个。

//#导入"BTSimpleSideMenuClass.h"

//#导入"BTSimpleMenuItemClass.h"

创建对象

var objBTSimpleSideMenuClass = BTSimpleSideMenuClass()

导入委托

class YourClassName: UIViewController, BTSimpleSideMenuDelegate {

}

从 ViewDidLoad 或 ViewWillAppear 调用此方法并传递包含名称、图像等的数组

func setupOptionMenu(noOfItems : NSMutableArray)
{
    objBTSimpleSideMenuClass.delegate = self

    let ary : NSMutableArray = []

    for var i = 0; i < noOfItems.count; i++
    {
        let item = BTSimpleMenuItemClass.init(title: noOfItems[i] as! String, image: nil) { (success, item) -> Void in


            self.methodOptionMenuTap1()

            //self.methodOptionMenuTap2()

            //self.methodOptionMenuTap3() 

        }

        ary.addObject(item)
    }

    let swiftArray = ary as NSArray

    objBTSimpleSideMenuClass =  BTSimpleSideMenuClass.init(item: swiftArray as [AnyObject], addToViewController: self)



}

希望对您有所帮助。

祝一切顺利。