添加按钮添加 uitextfield 的子视图 ios swift

add button ad sub view of uitext field ios swift

我有两个按钮,即 programsdata。这两个按钮有下拉 option.But 当我 select 第一个下拉选项 program 如果我 select 来自下拉列表的任何数据。比如我 select "super" 来自下拉列表。然后那个超级词 select 在我的两个按钮中。

没有 select 我的第二个按钮下拉 option.Its 自动 changing.For 很明显,如果我 select super 数据来自 program 按钮,那个词 "super" 正在我的两个下拉按钮中更新。

请帮我解决这个问题:

这是我的代码:

import UIKit

class UserDetailsController: UIViewController {

    var addString: String!

      let dropDown = DropDown()




    @IBOutlet weak var programBtn: UIButton!


    @IBOutlet weak var dataBtn: UIButton!


        override func viewDidLoad() {
        super.viewDidLoad()

        dropdownmethod()


    }




    func dropdownmethod () {


        dropDown.dataSource = [
            "Car",
            "Motorcycle",
            "Van",
            "Truck",
            "Bus",
            "Bicycle",
            "Feet",
            "add"
        ]

        dropDown.selectionAction = { [unowned self] (index, item) in
            self.SpectifBtn.setTitle(item, forState: .Normal)
              self.organBtn.setTitle(item, forState: .Normal)

            if item == "add" {

                if #available(iOS 8.0, *) {
                    let alert = UIAlertController(title: "Duplicate file", message: "Afile with the same name already exists.", preferredStyle:
                        UIAlertControllerStyle.Alert)
                    alert.addTextFieldWithConfigurationHandler(self.configurationTextField)

                    alert.addAction(UIAlertAction(title: "Ok", style: UIAlertActionStyle.Default, handler:{ (UIAlertAction)in
                        print("User click Ok button")
                        print(self.textField.text)
                        self.addString = self.textField.text
                        self.dropDown.dataSource =  [   "Car",
                            "Motorcycle",
                            "Van",
                            "Truck",
                            "Bus",
                            "Bicycle",
                            "Feet", "\(self.addString)", "add"]
                        self.SpectifBtn.setTitle(self.addString, forState: .Normal)
                         self.organBtn.setTitle(self.addString, forState: .Normal)


                    }))

                    self.presentViewController(alert, animated: true, completion: {
                        print("completion block")
                    })

                } else {
                    // Fallback on earlier versions
                }
            }
        }

        dropDown.cancelAction = { [unowned self] in
            self.dropDown.selectRowAtIndex(0)
            self.SpectifBtn.setTitle("Canceled", forState: .Normal)
             self.organBtn.setTitle("Canceled", forState: .Normal)
        }

        dropDown.anchorView = SpectifBtn
        dropDown.bottomOffset = CGPoint(x: 0, y:SpectifBtn.bounds.height)
        dropDown.dismissMode = .Automatic

        dropDown.selectRowAtIndex(3)

    }




    func configurationTextField(textField: UITextField!)
    {
        if let aTextField = textField {
            textField.text = "Filename"
            self.textField = aTextField

        }
    }

    @IBAction func programBtnPressed(sender: AnyObject) {


        if dropDown.hidden {
            dropDown.show()
        } else {
            dropDown.hide()
        }
    }


    @IBAction func dataBtnPressed(sender: AnyObject) {

        if dropDown.hidden {
            dropDown.show()
        } else {
            dropDown.hide()
        }


    }





}

我的屏幕 shot.When 我 select 我的 program drop down.That 选项名称中的任何选项也在我的 data 按钮名称中自动更新

在某些项目下拉 selection 之后,你应该检查它来自哪个按钮(例如通过标签),现在看来你只是 select 它们都在这里:

self.SpectifBtn.setTitle(item, forState: .Normal) self.organBtn.setTitle(item, forState: .Normal)