How to create DropDown in xcode?

后端 未结 5 1821
时光取名叫无心
时光取名叫无心 2020-11-27 17:55

I am a very new developer for IOS, i need help, How to create dropdown box in xcode, any one provide me example to create country list in drop down?

5条回答
  •  栀梦
    栀梦 (楼主)
    2020-11-27 18:35

    Since there are no native DropDown elements in iOS, you could make use of a TextField with custom background and a UITableView to accomplish that. Here is how to go about it.

    Pseudocode

    • Create a TextField and set it's delegate to parent controller
    • Implement UITextFieldDelegate and implement the textFieldShouldBeginEditing method
    • Create a new UIViewController and implement UITableView in it programmatically.
    • Create a custom protocol and create it's object (delegate) it.
    • In textFieldShouldBeginEditing method, load this controller and present it modally passing the required table's data source and set delegate as parent.
    • in the new tableViewController, implement UITableViewDelegate and implement the didSelectRowAtIndex path method.
    • Upon row selection, call the delegate with passing appropriate data.
    • dismiss the modally presented controller.

提交回复
热议问题