如何提出一组可选的安全问题

How to present set of optional security questions

我需要在单击按钮时显示可能的问题列表,并且在单击按钮后必须将其放在文本字段中。提出问题的最佳方式是什么。

在上图中,单击箭头按钮时我需要显示可能的问题列表

我已经实现了以下是不是有更好的方法

#pragma mark - pickerview

-(void)pickerview:(id)sender
{
    pickerView=[[UIPickerView alloc] initWithFrame:CGRectMake(0,[Util window_height]-260,[Util window_width],300)];
    // pickerView.transform = CGAffineTransformMakeScale(0.75f, 0.75f);
  //  pickerView.transform = CGAffineTransformMakeScale(0.85f, 0.85f);
    pickerView.delegate = self;
    pickerView.dataSource = self;
    pickerView.showsSelectionIndicator = YES;
    pickerView.backgroundColor = [UIColor lightGrayColor];
    [pickerView selectRow:1 inComponent:0 animated:YES];
    [self.view addSubview:pickerView];
   // [contentView addSubview:pickerView];

}

- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView;
{
    return 1;

}

- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component;
{

    return [_items count];
}

- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component
{
        return[_items objectAtIndex:row];

}

-(void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component{

    [pickerView removeFromSuperview];
    [Txt_SecurityQue setText:[_items objectAtIndex:row]];
     NSLog(@"Did select");
}


#pragma mark - securityQuestionsArray

-(void)securityQuestionsArray {

    _items =[[NSArray alloc]initWithObjects:
             @"Where do you want to retire?",
             @"Where did you vacation last year?",
             @"What is your personal address",
             @"What is your employer name",
             @"Who is your nearest relative",
             @"What is your best friend phone number",
             @"In what city were you born?",
             @"What was your childhood nickname?",
             @"Type your own question.",
             @"What was the make and model of your first car?",
             @"What time of the day was your first child born?",
             @"What is your oldest sibling’s birthday month and year?",
             @"What was your childhood nickname?",
             @"What is the name of your favorite childhood friend?",
             @"In what city or town did your mother and father meet?",
             @"What is the middle name of your oldest child?",
             @"What is your favorite team?",
             @"What is your favorite movie?",
             @"What was your favorite sport in high school?",
             @"What was your favorite food as a child?",
             @"What is the first name of the boy or girl that you first kissed?",
             @"What was the make and model of your first car?",
             @"What was the name of the hospital where you were born?",
             @"Who is your childhood sports hero?",
             @"What school did you attend for sixth grade?",
             @"What was the last name of your third grade teacher?",
             @"what town was your first job?",
             @"What was the name of the company where you had your first job?",
                          nil];

}

这需要 iOS 上的自定义控件,"Combo box" 中没有像 OS X 中那样的内置控件。您可以尝试使用自定义 UIView 自己构建一个控件,或者使用类似于 this link (codeproject.com)。他们有我认为您要求的示例代码。

这不是一件容易实现的事情,因为 iOS 不提供本机下拉列表。如果您想使用下拉按钮,则必须在箭头所在的位置放置一个 UIButton,点击它后,您必须在 UITextField 下方填充一个 UITableView。这需要您做大量的工作,但完全有可能。

此外,您可以使用内置的 UIPickerView

使用选择器视图和按钮。单击按钮仅显示选择器视图,选择后,关闭选择器。

array_from=[[NSMutableArray alloc]initWithObjects:
                @"In what city were you born?",
                @"What was your childhood nickname?",
                @"Type your own question.",
                nil];


- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component
{
    NSUInteger numRows = [array_from count];
    return numRows;
}
- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView
{
    return 1;
}

- (UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)view
{

    UILabel *label = [[UILabel alloc] initWithFrame:CGRectZero];
    [label setText:[array_from objectAtIndex:row]];
    [label setTextAlignment:NSTextAlignmentCenter];
    label.adjustsFontSizeToFitWidth = YES;
    return label;
}