2015-04-12 47 views
0

iOS 8
Xcode 6.3
我有一個選擇器視圖,它有2個組件。一旦用戶點擊文本框,我就會帶來選擇器視圖。 一旦用戶在選取器視圖中選擇一個值,它就會消失! 請參見下面的代碼:iOS的UIPickerview消失在didSelectRow

- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component { 
    if (component == 0) { 
     ccYearTF.text = [NSString stringWithFormat:@"%i", [pickerView selectedRowInComponent:0] + 2015]; 
    } 
    else { 
     ccMonthTF.text = [NSString stringWithFormat:@"%02d", [pickerView selectedRowInComponent:1] + 1]; 
    } 
} 

如果我不把它正常工作,並不會消失的文本框的值,但如果我設置文本框的值,然後消失。誰能說出爲什麼會發生這種情況?

+0

拾取器是否查看文本字段的'inputView'?文本字段是否退出第一響應者(將隱藏輸入視圖)? – rmaddy

+0

選擇器視圖不是文本字段的inputView。我只是在文本字段被點擊時調出選擇器視圖。當從選擇器中選擇一個值時,我將其設置爲文本字段。 – Artin

+0

你能告訴我們TextField委託的代碼嗎?當textField成爲第一響應者時,以及在它調用shouldChangeText時發生了什麼。 – pteofil

回答

0

我認爲你正在嘗試做這樣的事情,我有類似的問題,只有在iOS 8 檢查這個問題太iOS8: What's going on with moving views during keyboard transitions? 不要用故事板

//Do not link with storyboard 
@property UIPickerView *pickerview; 
//in view didload 
self.pickerview = [[UIPickerView alloc] initWithFrame:CGRectMake(self.view.frame.size.width+1,ccYearTF.frame.origin.y+60,self.view.frame.size.width, 150)]; 
self.pickerview.dataSource = self; 
self.pickerview.delegate = self; 
[self.view addSubview:self.pickerview]; 
當你按下ccYearTf textfiled

-(void)textFieldDidBeginEditing:(UITextField *)textField 
    { 
    if(textField == ccYearTf) 
    { 
     [textField resignFirstResponder]; 
     [UIView animateWithDuration:0.7f delay:0 options:UIViewAnimationOptionCurveLinear animations:^{ 
      [self.pickerview setFrame:CGRectMake(0, _pickerview.frame.origin.y, self.view.frame.size.width, _pickerview.frame.size.height)]; 
     }completion:nil]; 
     } 
    } 
現在

上 'pickerView didSelectRow' 你pickerview不會消失 希望這有助於

0

感謝您的回覆。但是,我已經在一週前聯繫了Apple技術支持,最後他們回覆了。 以下是他們建議的內容:

當進行選擇時,UIPickerView消失的問題可能是一個錯誤。請考慮在http://bugreport.apple.com提交錯誤報告,並附上您的示例項目。作爲解決方法,請以編程方式創建選取器視圖和工具欄,並且只根據需要進行。

我還沒有嘗試手動添加選擇器,但我提交了一個錯誤報告。一旦修復,我會在這裏更新。