I have Xcode 4.2 and I am trying to create a drop down menu. I would like the drop down menu to drop down with words or numbers. Then when I select something from the list I would like it to appear in a table on a different page. My question is: how would I write this?
Thanks
I have Xcode 4.2 and I am trying to create a drop down menu.
Share
First create a UIViewController subclass with a nib file by going File > New > New File and following the prompts.
Now open the nib (MyViewController.xib).
You should drag a UIPickerView and a UITableView into the view and arrange them however you like (it doesn’t matter).
Next open the header file (MyViewController.h) for your UIViewController subclass.
At the end of the
line add
<UITableViewDelegate, UITableViewDataSource, UIPickerViewDelegate, UIPickerViewDataSource>so it looks like thisNext you will need to add references to your tableview and picker and also two arrays of values. Just above
@endadd the following linesThen just go back to your nib file and connect the UITableView and UIPickerView to these variables.
Now in your source file (MyViewController.m) you need to synthesize you references. So add
@synthesize tableView, pickerView, tableData, pickerDatato the file just below@implementation MyViewControllerNow to add the delegate methods, there will be quite a few of them, but they’re pretty self explanatory.
The delegate methods for the UITableView are
The delegate methods for the UIPickerView are
They should be added to the source file and used as follows
UITableView:
UIPickerView:
Ok, the final thing you have to do is set the delegates and initialise the data. In the
- (void)viewDidLoadmethod ofMyViewControlleradd the following linesThere are a few more delegate methods which you can find in the spec for the classes but these ones should be adequate for now.