开发者

UITextfield mimic Dropdown (UITableView?)

开发者 https://www.devze.com 2023-04-02 23:07 出处:网络
I want to add the feature that when i tap on a specific textfield, then there is a Dropdown / TableView in front of the gui and i can se开发者_开发问答lect a value and then the selected value is then

I want to add the feature that when i tap on a specific textfield, then there is a Dropdown / TableView in front of the gui and i can se开发者_开发问答lect a value and then the selected value is then inserted into the textfield?

How to achieve this in the easiest way?


Depends, if this is on the iPad, you can use UIPopoverController and present a UITableViewController inside it.

If not, you can present a UIActionSheet and add UIPickerView or a UITableView inside it...in this example, I am creating a UIActionSheet and placing a UIPickerView inside it:

    NSString *title = UIDeviceOrientationIsLandscape([UIDevice currentDevice].orientation) ? @"\n\n\n\n\n\n\n\n\n" : @"\n\n\n\n\n\n\n\n\n\n\n\n" ;
            UIActionSheet *actionSheet = [[UIActionSheet alloc] 
                                          initWithTitle:[NSString stringWithFormat:@"%@%@", title, [entry objectForKey:@"Name"]]
                                          delegate:nil cancelButtonTitle:nil destructiveButtonTitle:nil otherButtonTitles:@"Ok", nil];
[actionSheet setDelegate:self];
[actionSheet setTag:row];

pv = [[UIPickerView alloc] init];
[pv setShowsSelectionIndicator:YES];
[pv setDelegate:self];
[pv setTag:28];
[actionSheet addSubview:pv];
[actionSheet showInView:[[[self navigationController] tabBarController] view]];
[pv release];

Notice the "\n"s, you need those to make room for the Picker view. Here's the result:

UITextfield mimic Dropdown (UITableView?)

0

精彩评论

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

关注公众号