Search code examples
iosobjective-cuipickerview

How to present set of optional security questions


I need to present the list of possible questions while clicking the button and after clicking the button it must be placed inside the text field. What is the best way to present the questions. enter image description here

enter image description here

In the above image while clicking the arrow button I need to present the list of possibles questions

I have implemented the following is there some better ways then that

#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];

}

Solution

  • Use a picker view and button. On the click of button just show the picker view and after selection, just dismiss the picker.

    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;
    }