Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create DropDown in xcode?

Tags:

xcode

iphone

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?

like image 253
Adnan Khan Avatar asked Nov 20 '12 05:11

Adnan Khan


5 Answers

Here I found two demos for dropDown list, One is creating custom expandable UITableViewCell like :-

enter image description here

to

enter image description here

source code :- DEMO

AND Another is custom Drop Down list like:-

enter image description here

by clicking of test then open drop down list as bellow like image

drop down list

source code with Tab Bar:-DEMO

updated source code without Tab Bar :-

http://www.sendspace.com/file/83qws5

like image 130
Nitin Gohel Avatar answered Oct 28 '22 05:10

Nitin Gohel


I beleive you shouldn't use dropdown boxes in iOS, as it's a desktop OS UI control element. You should think up something else using existing components (like PickerView), that's the words for UI consistency.

And if you need this anyway, you may create a table view, place it beneath your label and a triangular button(which causes it to appear and disappear) and populate it with values.

like image 42
MANIAK_dobrii Avatar answered Oct 28 '22 06:10

MANIAK_dobrii


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.
like image 41
atastrophic Avatar answered Oct 28 '22 05:10

atastrophic


just for whom searching for small simple swift combo box here in 2016 year, i've tried a few of old and new (but obj-c) libs, and at last selected this:

https://github.com/sw0906/SWCombox

here is screenshot: enter image description here

like image 2
djdance Avatar answered Oct 28 '22 06:10

djdance


The easy and simple way to design a drop down list is by representing it like a UITableView and some animation. This makes it look really like a dropdownlist. Here is a code I used for creating one . For this first import the < QuartzCore/QuartzCore.h > framework.

-(IBAction)DropDownTable:(id)sender
{
TableView.hidden = NO;
if(TableView.frame.origin.y ==203)
{
    [UIView beginAnimations:nil context:NULL]; 
    [UIView setAnimationDuration:0.5f];
    [TableView setFrame:CGRectMake(224, 204, 27, 160)];
    [UIView commitAnimations];
    [self.view TableView];
}

else if (TableView.frame.origin.y == 204)
{
    [TableView setFrame:CGRectMake(224, 203, 27, 0)];
    TableView.hidden = YES;
}

[self.view addSubview:TableActivityLevel];
}

First make a tableview , declare its methods and make the array . Put this function on the click of a UIButton and youll see it work !!! Happy coding :)

like image 1
IronManGill Avatar answered Oct 28 '22 07:10

IronManGill