0

I want for a given label Example: Typemarital (possible answers: married, single, PACS, divorced, etc ...) to choose from a predefined list and know how to freeze the answers to a user on a field and not a view (without using the builder interface ) just through the code . Thanks

0

4 Answers 4

0

It can be made using a button and and a picker view.

1) On click of button, you have to show the picker view and from picker you have to select the value you want. Then from inputAccessoryView of picker view in which you can add a toolbar with done button.

2) On done button click you can get selected value of the picker and hide the picker.

3) The selected value then you can show it into a UILabel.

Hope this helps you.

EDIT:

Here is a very useful tutorial for dropdownmenu in iPhone/iPad:

http://kshitizghimire.com.np/dropdown-in-iphoneipad/

1
  • @Zouair Jouadi: I have added a tutorial in EDIT Section of my answer. Aug 30, 2011 at 9:57
0

Its quite simple actually. On click of label create a view and inside it create a table view where you can display list you require, and by simply clicking on cell i.e.

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath

place text of selected cell to your label and remove your view.

Hope it helps.....

4
  • can you be more clear please, at any case, i'll have to use the builder interface i guess, right ? there is no possibility to add a method or a function to the code existing ?? Aug 30, 2011 at 7:44
  • @ Zouair Jouadi: It can be made using a button and and a picker view Aug 30, 2011 at 8:49
  • yeah I thought about the UIPickerView as well , but how can I create a pickerview and make the connexion with a label Aug 30, 2011 at 8:53
  • @ Zouair Jouadi: Just put a custom button about your label and you can create custom view UIView *view = [[UIView alloc] initWithFrame: ] and then add UItableView inside this view. Hope it helps you
    – P.J
    Aug 30, 2011 at 8:55
0

you have to use UITableView.

1) Create a button with title.

2) when clicked on button tableView will be shown.

3) when one of the row of tableview would selected the tableview goes hide and the button title would be row selected in tableview..

0

You can use UIActionSheet. Add UIPickerView in UIActionSheet.

On tap of a button Try this:

category = [[UIActionSheet alloc] initWithTitle:nil delegate:self cancelButtonTitle:nil destructiveButtonTitle:nil otherButtonTitles:nil]; category.actionSheetStyle = UIActionSheetStyleBlackTranslucent;

UIPickerView *categoryPicker = [[UIPickerView alloc] initWithFrame:CGRectMake(0,50,  320, 120)];
categoryPicker.delegate = self;
categoryPicker.dataSource = self;
categoryPicker.showsSelectionIndicator = YES;
[categoryPicker selectRow:1 inComponent:0 animated:NO]; 
[category addSubview:categoryPicker];

UISegmentedControl *segmentedControlDone = [[UISegmentedControl alloc] initWithItems:[NSArray arrayWithObject:@"Done"]];

segmentedControlDone.momentary = YES;
segmentedControlDone.frame = CGRectMake(260, 7, 50, 30);
segmentedControlDone.segmentedControlStyle = UISegmentedControlStyleBar;
segmentedControlDone.tintColor = [UIColor blackColor];

[segmentedControlDone addTarget:self action:@selector(actionPickerDone) forControlEvents:UIControlEventValueChanged];

    [category addSubview:segmentedControlDone];

// implement data source method of UIPicker also

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.