【发布时间】:2011-09-07 12:21:48
【问题描述】:
我想添加一个功能,当我点击特定的文本字段时,gui前面有一个下拉/表格视图,我可以选择一个值,然后将选定的值插入到文本字段中?
如何以最简单的方式实现这一点?
【问题讨论】:
标签: uitableview ios4 xcode4 uitextfield
我想添加一个功能,当我点击特定的文本字段时,gui前面有一个下拉/表格视图,我可以选择一个值,然后将选定的值插入到文本字段中?
如何以最简单的方式实现这一点?
【问题讨论】:
标签: uitableview ios4 xcode4 uitextfield
视情况而定,如果这是在 iPad 上,您可以使用 UIPopoverController 并在其中呈现一个 UITableViewController。
如果没有,您可以呈现一个 UIActionSheet 并在其中添加 UIPickerView 或 UITableView...在此示例中,我正在创建一个 UIActionSheet 并在其中放置一个 UIPickerView:
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];
注意“\n”,您需要这些为 Picker 视图腾出空间。结果如下:
【讨论】: