2009-05-25 13 views
9

मैं यूआईटीक्स्टफील्ड के फर्स्ट रेस्पॉन्डर बनने पर एक यूआईपीकर व्यू दिखाना चाहता हूं, कीबोर्ड नहीं और पाठ फ़ील्ड में मान को पिकर व्यू फॉर्म भरें।यूटेक्स्टफील्ड में पिकर्विव को कीबोर्ड कैसे नहीं दिखाना है?

कोई भी यह जानता है?

उत्तर

25

संपादित करें: इस उत्तर लेखन के समय सही था। ऐप्पल ने तब से inputView पेश किया है। माफोन्या answer आजकल आपको क्या करना चाहिए।

कीबोर्ड को पॉप-अप करने से रोकना संभव है। अपनी कक्षा को UITextField के प्रतिनिधि बनने के लिए सेट करें: textField.delegate = self और हेडर फ़ाइल में अपने इंटरफ़ेस घोषणा ({से पहले) के बाद <UITextFieldDelegate> जोड़ें।

अब textFieldShouldBeginEditing: लागू:

- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField { 
    // Show UIPickerView 

    return NO; 
} 

आप अपने pickerView इस विधि काम नहीं करेगा को छिपाने के लिए सक्षम होने के लिए चाहते हैं। आप क्या कर सकते हैं तो UITextField के उप-वर्ग बनाएं और *trackingWithTouch:event: चयनकर्ताओं को ओवरराइड करें और उन में अपना जादू करें। कीबोर्ड को दिखाने से रोकने के लिए आपको शायद textFieldShouldBeginEditting: से कोई भी वापस लौटने की आवश्यकता नहीं है।

+1

आपका समाधान आंशिक रूप से काम करता है। मैं कुछ विशिष्ट uitextfields पर पिकर व्यू को सभी टेक्स्ट फ़ील्ड पर नहीं दिखाना चाहता हूं और जब वांछित टेक्स्ट फ़ील्ड में भरे पिकर व्यू से मूल्य चुना जाता है तो पिकर व्यू छुपाया जाना चाहिए। –

1

पर कोड बाहर चेक

UITextView and UIPickerView with its own UIToolbar

इस pickerview इस्तीफा देने के लिए मिल जाएगा (दोनों TextView + tabbar और pickerview + tabbar कोड है) आदि सभी यू तो क्या करने की जरूरत pickerview का उपयोग करें पाठ दृश्य को अपडेट करने के लिए प्रतिनिधि विधि

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

टेक्स्टफील्ड का उपयोग करने के बजाय, एक सफेद पृष्ठभूमि के साथ UIlabel का उपयोग करें। इस तरह जब आप इसे टैप करते हैं तो कीबोर्ड नहीं दिखाया जाएगा। UILabel पर छूने की घटना को ओवरराइड करें, जब ऐसा होता है तो विधि को गोपनीय प्रश्न कहते हैं जो नया दृश्य प्रदर्शित करेगा।

-(void) addToViewWithAnimation:(UIView *) theView 
+0

मैं कुंजीपटल केवल पिकर दृश्य मैं जब मैं पाठ क्षेत्र –

+0

हाँ कुंजीपटल काफी हमेशा दिखाई देगा में प्रवेश करती है प्रदर्शित करना चाहते हैं है दिखाने के लिए नहीं चाहते। आपको uiLabel जैसे किसी अन्य दृश्य का उपयोग करना होगा। मैंने जवाब को अधिक संक्षेप में संपादित किया है। – Bluephlame

+0

ब्लू का उल्लेख किया गया है, कीबोर्ड हमेशा दिखाई देगा और आप इससे बच नहीं सकते हैं।एक और विकल्प कुंजीपटल के शीर्ष पर एक पिकर दृश्य जोड़ना होगा। वे एक ही ऊंचाई हैं, इसलिए कीबोर्ड नहीं देखा जाएगा। – lostInTransit

4

अरे मैंने कुछ परिदृश्य में चिपकाया है जिसे मैंने कुछ समय पहले इस परिदृश्य को कवर करने के लिए लिखा था। वहाँ दो उदाहरण एक actionsheet साथ एक और एक एक actionsheet बिना कर रहे हैं:

- (void)textFieldDidBeginEditing:(UITextField *)myTextField{ 

      [myTextField resignFirstResponder]; 

      actionSheet = [[UIActionSheet alloc] initWithTitle:nil delegate:self cancelButtonTitle:nil destructiveButtonTitle:nil otherButtonTitles:nil]; 

      [actionSheet setActionSheetStyle:UIActionSheetStyleBlackTranslucent]; 

      CGRect pickerFrame = CGRectMake(0, 40, 0, 0); 

      UIPickerView *pickerView = [[UIPickerView alloc] initWithFrame:pickerFrame]; 

       pickerView.showsSelectionIndicator = YES; 

       pickerView.dataSource = self; 

       pickerView.delegate = self; 

       [actionSheet addSubview:pickerView]; 

       [pickerView release]; //NB this may result on the pickerview going black the next time you come back to the textfield, if this is the case just remove this statement 

       UISegmentedControl *closeButton = [[UISegmentedControl alloc] initWithItems:[NSArray arrayWithObject:NSLocalizedString(@"SUBMIT", @"")]]; 

       closeButton.momentary = YES; 

       closeButton.frame = CGRectMake(260, 7.0f, 50.0f, 30.0f); 

       closeButton.segmentedControlStyle = UISegmentedControlStyleBar; 

       closeButton.tintColor = [UIColor blackColor]; 

       [closeButton addTarget:self action:@selector(dismissActionSheet:) forControlEvents:UIControlEventValueChanged]; 

       [actionSheet addSubview:closeButton]; 

       [closeButton release]; 

       [actionSheet showInView:displayedInView]; 

       [actionSheet setBounds:CGRectMake(0, 0, 320, 485)]; 

} 

यह actionsheet बिना कोड है: http://www.buggyprogrammer.co.uk/2010/08/18/open-uipickerview-when-user-enters-textfield/

:

- (void)textFieldDidBeginEditing:(UITextField *)myTextField{ 

     [myTextField resignFirstResponder]; 

      for (int component = 0; component &lt; (((NSInteger)numberOfComponentsForPickerView) - 1); component++) { 

       NSInteger valueForRow = [[self.textField.text substringWithRange:NSMakeRange(component,1)] integerValue]; 

       [pickerView selectRow:valueForRow inComponent:component animated:YES]; 

      } 

      [self fadeInPickerView]; 

      [view addSubview:pickerView]; 

      [pickerView release]; 

} 

इस का एक अधिक विस्तृत उदाहरण में पाया जा सकता

28

[टेक्स्टफील्ड सेट इनपुट दृश्य: पिकर व्यू] का उपयोग करें;

प्रणाली इनपुट की जगह पाठ फ़ील्ड के लिए दृश्य
inputView
inputAccessoryView

+7

यह उन लोगों के लिए सही उत्तर है जो जानते हैं कि वे क्या कर रहे हैं। –

+0

मैं सहमत हूं, यह सही जवाब है। –

+1

क्या आप लोग इसके त्वरित कार्यान्वयन को जानते हैं? – kareem

4

ऐड inputview।

picker = [[UIPickerView alloc]init]; 
[picker setDataSource:self]; 
[picker setDelegate:self]; 
[picker setShowsSelectionIndicator:YES]; 

MyTextField.inputView = picker; 
+0

धन्यवाद! यह मेरे लिए काम करता है लेकिन जब हमने कोई विकल्प चुना है तो पिकर को कैसे छिपाना है? बहुत बहुत धन्यवाद –

+0

मेरे लिए काम किया। धन्यवाद –

संबंधित मुद्दे