如何在swift中单击更改工具栏按钮

时间:2015-06-17 23:22:55

标签: ios swift uibarbuttonitem uitoolbar

我正在尝试将工具栏按钮项从“开始”更改为“步骤”,单击“开始”。我尝试在“开始”按钮的操作下使用self.toolbar.startBarButtonItem = nil将“开始”按钮==设置为nil,但这不起作用。我猜它与self.navigationItem.leftBarButtonItem = nil的工作方式不同。我可以在startAction()函数中添加什么来将按钮从开始更改为步骤?

import UIKit
import MapKit
import CoreLocation

class PickupViewController: UIViewController, MKMapViewDelegate, CLLocationManagerDelegate{

let toolbar = UIToolbar()

func configureToolbar() {

    //Creates the toolbar 

    toolbar.frame = CGRectMake(0, self.view.frame.size.height - 45, self.view.frame.size.width, 0)
    toolbar.sizeToFit()
    toolbar.backgroundColor = UIColor.whiteColor()
    self.view.addSubview(toolbar)
    var flexSpace = UIBarButtonItem(barButtonSystemItem: UIBarButtonSystemItem.FlexibleSpace, target: nil, action: nil)
    let toolbarButtonItems = [
        locationBarButtonItem, flexSpace, startBarButtonItem
    ]
    toolbar.setItems(toolbarButtonItems, animated: true)

}

// UIBarButtonItem Creation and Configuration
// Change the action from nil to getting the users current location

var locationBarButtonItem: UIBarButtonItem {
    return UIBarButtonItem(image: UIImage(named: "compass_2.png"), style: UIBarButtonItemStyle.Plain, target: self, action: "currentLoc")
}

var startBarButtonItem: UIBarButtonItem {
    return UIBarButtonItem(title: "Start", style: UIBarButtonItemStyle.Plain, target: self, action: "startAction")
}

var steps: UIBarButtonItem {
    return UIBarButtonItem(title: "Steps", style: UIBarButtonItemStyle.Plain, target: self, action: nil)
}

func startAction(){
}

0 个答案:

没有答案