开发者

how is a drop-down list made on the iphone?

开发者 https://www.devze.com 2023-03-31 12:02 出处:网络
I want for a given label Example: Typemarital (p开发者_开发百科ossible answers: married, single, PACS, divorced, etc ...) to choose from a predefined list and know how to freeze the answers to a user

I want for a given label Example: Typemarital (p开发者_开发百科ossible 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


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/


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.....


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..


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

0

精彩评论

暂无评论...
验证码 换一张
取 消