我有什麼是3 textFields和每當我觸摸textField1或textField2選取器更改值,並沒有鍵盤。當我觸摸textField3鍵盤出現,選取器隱藏。現在,如果我通過單擊返回,然後單擊textField1選擇器退出鍵盤,但如果我不不關閉鍵盤按鈕保持在選擇器。當鍵盤firstResponder我需要的是(我看到它在屏幕上)來隱藏它,如果我在textField1的點擊,只看到拾取UIPicker和鍵盤衝突
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];
}
羅伯特這不工作,要麼你被初始化'重新錯了。親愛的 – Spire 2010-12-03 11:22:45
@spire這絕對的作品,但它對你如何使用這根據you.and這就是答案編輯由Ishu – Ishu 2010-12-03 11:43:13