我正在尝试将工具栏按钮项从“开始”更改为“步骤”,单击“开始”。我尝试在“开始”按钮的操作下使用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(){
}