【问题标题】:UITextfield mimic Dropdown (UITableView?)UITextfield 模仿下拉(UITableView?)
【发布时间】:2011-09-07 12:21:48
【问题描述】:

我想添加一个功能,当我点击特定的文本字段时,gui前面有一个下拉/表格视图,我可以选择一个值,然后将选定的值插入到文本字段中?

如何以最简单的方式实现这一点?

【问题讨论】:

    标签: uitableview ios4 xcode4 uitextfield


    【解决方案1】:

    视情况而定,如果这是在 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 视图腾出空间。结果如下:

    【讨论】:

    • 我收到很多错误和警告(未声明的标识符“自我”?)
    • 使用未声明的标识符 'entry', [actionSheet setDelegate:self]; => 预期标识符或'(',使用未声明的标识符'row',[pv setShowsSelectionIndicator:YES]; => 预期标识符或'('
    • 好的,这些都是简单的修复,请阅读一些有关编程的书籍/指南并从基础开始。
    • 好吧,我需要一个有效的示例,以及一个小教程,如果您在 1 周内开发了一个应用程序(只是pickerview 缺少的部分)并且在发布之前很短,那么我将如何实现这一点然后开始阅读苹果的巨量文档(以及糟糕的文档)或整整 500 页的书?
    • 我也想要一个没有 actionsheet 和 tableview 的解决方案,就像问题中写的一样!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-11-18
    • 2019-04-04
    • 2011-07-08
    • 1970-01-01
    • 1970-01-01
    • 2021-12-05
    相关资源
    最近更新 更多