2017-02-16 75 views
0

應該raise.in選擇器視圖我又增加了這樣在文本框點擊pickerview改變文本框輸入視圖從pickerview到鍵盤在SWIFT 3.0

picker.delegate = self 
picker.dataSource = self 
picker.showsSelectionIndicator = true 
let toolBar = UIToolbar() 
toolBar.barStyle = UIBarStyle.default 
toolBar.isTranslucent = true 
toolBar.tintColor = UIColor.black 
    //UIColor(red: 76/255, green: 217/255, blue: 100/255, alpha: 1) 
toolBar.sizeToFit() 

let addbutton = UIBarButtonItem(title: "+Add", style: UIBarButtonItemStyle.plain, target: self, action: #selector(GBEDasboardViewController.addproducts)) 
let spaceButton = UIBarButtonItem(barButtonSystemItem: UIBarButtonSystemItem.flexibleSpace, target: nil, action: nil) 
let cancelButton = UIBarButtonItem(title: "Cancel", style: UIBarButtonItemStyle.plain, target: self, action: #selector(GBEDasboardViewController.addproducts)) 

toolBar.setItems([cancelButton, spaceButton, doneButton], animated: false) 
toolBar.isUserInteractionEnabled = true 

productname.inputView = picker 
productname.inputAccessoryView = toolBar 

上點擊Add按鈕pickerview工具應該關閉和鍵盤應提高

 func addproducts(){ 
     self.view.endEditing(true) 
    } 

pickerview正在關閉,但如何提高鍵盤。

+0

你想在同一個文本框的鍵盤和選擇器? –

+0

是初始選擇器視圖點擊添加選擇器視圖然後我應該得到鍵盤爲同一個文本框 –

回答

0

你應該用下面的代碼替換你的代碼。

let addbutton = UIBarButtonItem(title: "+Add", style: UIBarButtonItemStyle.plain, target: self, action: #selector(GBEDasboardViewController.addProducts)) 
let spaceButton = UIBarButtonItem(barButtonSystemItem: UIBarButtonSystemItem.flexibleSpace, target: nil, action: nil) 
let cancelButton = UIBarButtonItem(title: "Cancel", style: UIBarButtonItemStyle.plain, target: self, action: #selector(GBEDasboardViewController.endEditing)) 

func addProducts(){ 
     self.view.endEditing(true) 
     productname.inputView = nil 
     productname.becomeFirstResponder() 
} 

func endEditing() { 
    self.view.endEditing(true) 

} 
+0

你有沒有試過這個代碼? –

+0

謝謝你的工作 –

+0

那麼你能接受答案嗎? –