2017-02-16 35 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

那么你能接受答案吗? –