UITextField with a dropdown menu for iPhone

99封情书 提交于 2019-12-01 00:21:34

For drop down menu you can implement UITableView. You can populate this UItableview with your list.

Just declare it in ViewDidLoad method of your ViewController and then you can show or hid accordingly later.

    TableView = [[UITableView alloc]initWithFrame:CGRectMake(x,x,x,x) ];
    TableView.delegate = self;
    TableView.dataSource = self;

Add this to main view when user clickes on UITextField.

[self.view addSubView:TableView];

If you want user to select from given list only better option is UIButton instead of UITextField.

EDIT: I didn't notice it is the same as above answer.

Minakshi

You can show a down arrow button besides uitextfield. And add a tableview of width same as textfield and height whatever you want and place it exactly below the textfield and keep it hidden. On click to downarrow button make tableView.hidden = NO so that it will appear as dropdown and again in didSelectRowAtIndexPath function of tableview make it hidden and place the selected row value in textfield. That's it.

MohanVydehi

What you said is correct and we can also use textfield delegate method to populate the result in the table view, instead of using the down arrow. When the user enters some text in the in the text field, the text field delegate method (didChangeText Delegate Method) will be called, in that method you can update the table view. No need to add a dropdown arrow button in the text field.

easonoutlook

Just do this:

Add this to main view when user clickes on UITextField.

[self.view addSubView:TableView];
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!