複数のpickerViewを配置する例

下記がそれぞれの入力フィールド
@IBOutlet weak var chgBunrui: UITextField!
@IBOutlet weak var msgAdd: UITextField!
@IBOutlet weak var syochiAdd: UITextField!
@IBOutlet weak var syochiAdd2: UITextField!

```swift
    override func viewDidLoad() {
        super.viewDidLoad()
        let pickerView = UIPickerView()
        let pickerView2 = UIPickerView()
        let pickerView3 = UIPickerView()
        let pickerView4 = UIPickerView()
        
        pickerView.delegate = self
        pickerView.dataSource = self
        pickerView2.delegate = self
        pickerView2.dataSource = self
        pickerView3.delegate = self
        pickerView3.dataSource = self
        pickerView4.delegate = self
        pickerView4.dataSource = self
        pickerView.tag = 1
        pickerView2.tag = 2
        pickerView3.tag = 3
        pickerView4.tag = 4
        
        //inputView入力項目定義
        chgBunrui.inputView = pickerView
        msgAdd.inputView = pickerView2
        syochiAdd.inputView = pickerView3
        syochiAdd2.inputView = pickerView4
        
        
        let toolBar = UIToolbar()
        toolBar.barStyle = UIBarStyle.Default
        toolBar.translucent = true
        toolBar.tintColor = UIColor(red: 76/255, green: 217/255, blue: 100/255, alpha: 1)
        toolBar.sizeToFit()
        let doneButton = UIBarButtonItem(title: "Done", style: UIBarButtonItemStyle.Plain, target: self, action: #selector(PhotoAddViewController.donePicker))
        let spaceButton = UIBarButtonItem(barButtonSystemItem: UIBarButtonSystemItem.FlexibleSpace, target: nil, action: nil)
        let cancelButton = UIBarButtonItem(title: "Cancel", style: UIBarButtonItemStyle.Plain, target: self, action: #selector(PhotoAddViewController.cancelPicker))
        
        toolBar.setItems([cancelButton, spaceButton, doneButton], animated: false)
        toolBar.userInteractionEnabled = true
        
        //入力エリアアクセス宣言
        chgBunrui.inputAccessoryView = toolBar
        msgAdd.inputAccessoryView = toolBar
        syochiAdd.inputAccessoryView = toolBar
        syochiAdd2.inputAccessoryView = toolBar
```

```swift
    //表示列
    func numberOfComponentsInPickerView(pickerView: UIPickerView) -> Int {
        
        return 1
    }
    
    //表示個数
    func pickerView(picker: UIPickerView, numberOfRowsInComponent component: Int) -> Int {
        if(picker.tag == 1){
            return bunruiname.count
        }else if(picker.tag == 2){
            return doctorname.count
        }else if(picker.tag == 3){
            return syochiname.count
        }else{
            return syochi2name.count
        }
    }
    
    //表示内容
    func pickerView(picker: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String {
        if(picker.tag == 1){
            pickersw = 0
            return bunruiname[row] as String
        }else if(picker.tag == 2){
            pickersw = 1
            return doctorname[row] as String
        }else if(picker.tag == 3){
            pickersw = 2

            
            
            return syochiname[row] as String
        }else{
            pickersw = 3
            return syochi2name[row] as String
        }
    }
    
    //選択時
    func pickerView(picker: UIPickerView, didSelectRow row: Int, inComponent component: Int) {
        if(picker.tag == 1){
            //textw = "受付分類: \(bunruiname[row])"
            textw = bunruiname[row]
            idw = bunruiid[row]
        }else if(picker.tag == 2){
            //textw = "担当: \(doctorname[row])"
            textw = doctorname[row]
            idw = doctorid[row]
        }else if(picker.tag == 3){
            
            if(syori1id[row] == "99"){
                comment.text = ""
                syori1sel = ""
                setupSyochi2()
                textw = ""
            }else{
                syori1sel = "?syori1id=" + syori1id[row]
                setupSyochi2()
                textw = syochiname[row]
            }
            //textw = syochiname[row]
        }else{
            textw = syochi2name[row]
        }
    }
    
    func donePicker() {
        print("done")
        if(pickersw == 0){
            chgBunrui.text = textw
            bunid.text = idw
            comment.text = comment.text + textw + " "
        }else if(pickersw == 1){
            msgAdd.text = textw
            docid.text = idw
            comment.text = comment.text + textw + " "
        }else if(pickersw == 2){

            syochiAdd.text = textw
            syochiAdd2.text = ""
        }else{
            syochiAdd2.text = textw
            comment.text = comment.text + textw + "、"
        }
        view.endEditing(true)
        
    }
    func cancelPicker(){
        print("cancel")
        view.endEditing(true)
    }
```