UIPicker and Keyboard conflict

what i have is 3 textFields and whenever i touch textField1 or textField2 Picker changes values and there is no keyboard. When i touch textField3 keyboard appears and the picker goes hidden.Now if i dismiss the keyboard by clicking return and then click textField1 picker appears again, but if i dont dismiss the keyboard BY CLICKING BUTTON it stays over the picker. What I need is when the keyboard is firstResponder (and i see it on the screen) to hide it if i click on the textField1 and only to see the picker

int variabla;

    -(void)textFieldDidBeginEditing:(UITextField *)textField{
        [pickerView setHidden:YES];
        if (textField1.editing == YES) {
            [textField1 resignFirstResponder];
            [pickerView setHidden:NO];
            variabla = 1;
        }else if (textField2.editing == YES) {  
            [textField2 resignFirstResponder];
            [pickerView setHidden:NO];
            variabla = 2;
        }   
        NSLog(@"variabla %d",variabla); 
        [pickerView reloadAllComponents];
    }

    - (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView;
    {
        return 1;
    }
    - (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component;
    {
        if (variabla == 1) {
            return [pickerArray1 count];
        }else if (variabla == 2) {
            return [pickerArray2 count];
        }else {
            return 0;
        }   
    }
    - (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component;
    {   
        if (variabla == 1) {
            return [pickerArray1 objectAtIndex:row];        
        }else if (variabla == 2) {
            return [pickerArray2 objectAtIndex:row];
        }else {
            return 0;
        }   
    }
    - (void)textFieldShouldReturn:(UITextField *)textField{ 
        [textField resignFirstResponder];
    }
- (void)viewDidLoad {
    [super viewDidLoad];
    [pickerView setHidden:YES];
    pickerArray1 = [[NSMutableArray alloc] initWithObjects:@"0", @"1", @"2", nil];
    pickerArray2 = [[NSMutableArray alloc] initWithObjects:@"3", @"4", @"5", nil];
}

Answers


ok for solve this problem you can use lot of option i tell you one of them.

- (void)textFieldShouldBeginEditing:(UITextField *)textField {

  if([textField isEqual:yourTextField3])
  {
    yourPicker.hidden=YES;
  }
  else
  {

    [yourTextField3 resignFirstResponder];
    [self performSelector:@selector(textFieldFirstResponderOnDelay) withObject:nil afterDelay:0.3];
  }
}


- (void)textFieldFirstResponderOnDelay {
  yourPicker.hidden=NO;
}

And whatever you want you can put in to these conditions.

or you can add tag with your textfield and check accordingly.Hide picker whenever you want or display picker and hide keyboard whenever you want.


Need Your Help

How to integrate AIR with Windows superbar?

actionscript-3 flex winapi air progress-bar

I'm making a sort of batch processing application with Flex and AIR and I want to illustrate the progress of the batch. I'm using mx:ProgressBar, but this is not enough for me, I want to see the pr...

HTML5 semantics for multiple nav elements?

html5 semantics nav

I'm learning HTML5 and have been given a project of converting CSS Zen Gardens into a HTML5 semantic version. I've been able to convert most of it with ease, however the links / navigation at the b...

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.