2014-09-27 10 views
10

में कोई कीबोर्ड नहीं है मेरे पास एक पुराना एक्सकोड प्रोजेक्ट है जो आईओएस 6 और उच्चतर के लिए लक्षित है। मैं हाल ही में यह Xcode 6 में खोल दिया और iOS 8. के ​​लिए iPhone 6 सिम्युलेटर में भाग गया जब मैं इस कार्रवाई की कोशिश कीUIAlertView बनाम UIAlertController - आईओएस 8

UIAlertView* dialog = [[UIAlertView alloc] initWithTitle:@"Enter Folder Name" 
                message:@"Keep it short and sweet" 
                delegate:self 
              cancelButtonTitle:@"Cancel" 
              otherButtonTitles:@"OK", nil]; 

    dialog.alertViewStyle = UIAlertViewStylePlainTextInput; 
    dialog.tag = 400; 
    [dialog show]; 

मैं एक पॉप-अप विंडो मिलता है लेकिन जब मैं पाठ क्षेत्र पर क्लिक करें, कोई कुंजीपटल ऊपर आता है । मैंने googled और पढ़ा कि मुझे इसके बजाय UIAlertController का उपयोग करने की जरूरत है। चूंकि मुझे आईओएस 6, 7 संस्करणों का समर्थन करने की आवश्यकता है, इसलिए मैंने अपना कोड इस तरह बदल दिया।

if ([UIAlertController class]) 
    { 
     // use UIAlertController 
     UIAlertController *alert= [UIAlertController 
             alertControllerWithTitle:@"Enter Folder Name" 
             message:@"Keep it short and sweet" 
             preferredStyle:UIAlertControllerStyleAlert]; 

     UIAlertAction* ok = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault 
                handler:^(UIAlertAction * action){ 
                 //Do Some action here 
                 UITextField *textField = alert.textFields[0]; 
                 NSLog(@"text was %@", textField.text); 

                }]; 
     UIAlertAction* cancel = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleDefault 
                 handler:^(UIAlertAction * action) { 

                  NSLog(@"cancel btn"); 

                  [alert dismissViewControllerAnimated:YES completion:nil]; 

                 }]; 

     [alert addAction:ok]; 
     [alert addAction:cancel]; 

     [alert addTextFieldWithConfigurationHandler:^(UITextField *textField) { 
      textField.placeholder = @"folder name"; 
      textField.keyboardType = UIKeyboardTypeDefault; 
     }]; 

     [self presentViewController:alert animated:YES completion:nil]; 

    } 
    else 
    { 
     // use UIAlertView 
     UIAlertView* dialog = [[UIAlertView alloc] initWithTitle:@"Enter Folder Name" 
                 message:@"Keep it short and sweet" 
                 delegate:self 
               cancelButtonTitle:@"Cancel" 
               otherButtonTitles:@"OK", nil]; 

     dialog.alertViewStyle = UIAlertViewStylePlainTextInput; 
     dialog.tag = 400; 
     [dialog show]; 

    } 

फिर अगर मैं एक ही कार्रवाई कोई कुंजीपटल प्रदर्शित किया जाता है की कोशिश करो।

क्या यह एक्सकोड 6 सिम्युलेटर में एक बग है या मैं कुछ गलत कर रहा हूं?

enter image description here

+1

दबाने "कमांड" + "K" का प्रयास करें, हो सकता है आईओएस हार्डवेयर कीबोर्ड पता लगा रहा है तो यह नहीं है कीबोर्ड दिखा रहा है –

+0

सिम्युलेटर मेनू विकल्प में हार्डवेयर -> कीबोर्ड -> सॉफ़्टवेयर कीबोर्ड टॉगल करें – yazh

उत्तर

19

मैं इस परीक्षण किया गया, अगर iOS8 एक हार्डवेयर कीबोर्ड का पता लगाता है, की तुलना में यह कीपैड नहीं खोलता है। जैसा कि आप सिम्युलेटर में परीक्षण कर रहे हैं, इसलिए यह कोई भी कीपैड नहीं दिख रहा है

"कमांड" + "के" दबाएं और आपको कीपैड देखने में सक्षम होना चाहिए।

जब एक युक्ति यदि आप इस समस्या का सामना नहीं करना होगा, जब तक उपयोगकर्ता एक हार्डवेयर ब्लूटूथ कीपैड के साथ अपनी डिवाइस कनेक्ट है पर परीक्षण, तो यह कुछ नहीं है आप के बारे में

आशा चिंता करना चाहिए इस

+0

धन्यवाद दोस्त, यह जांचने के लिए। मैं आपका जवाब चिह्नित करूंगा। ओएनसी अधिक सवाल। अगर मैं केवल आईओएस 8 उपकरणों के लिए UIAlertView का उपयोग करता हूं, तो क्या वह कोड काम नहीं करेगा? मैंने सिम्युलेटर में कोशिश की और यह काम करता है –

+3

यह काम करेगा, लेकिन यह कम हो गया है, इसलिए ऐप्पल आने वाले आईओएस रिलीज में इसे रोक सकता है, इसलिए यह अच्छा अभ्यास है कि चित्रित विधियों का उपयोग न करें और अद्यतित रहें, लेकिन अभी के लिए यह कोई मुद्दा नहीं होना चाहिए –

2

एक और तरीका है में मदद करता है कुंजीपटल देखने के लिए एक कीबोर्ड प्रकार सेट कर रहा है। यह एक उदाहरण कोड हो सकता है: जब आप AlertController दिखाने

UIAlertController* alertController = [UIAlertController 
            alertControllerWithTitle:@"Test" 
            message:@"Testing keyboard" 
            preferredStyle:UIAlertControllerStyleAlert]; 
[alertController addTextFieldWithConfigurationHandler: ^(UITextField *tf) 
{ 
    tf.autocorrectionType = UITextAutocorrectionTypeYes; 
    tf.keyboardType = UIKeyboardTypeDefault; 
}]; 
[self presentViewController:alertController animated:YES completion:nil]; 

तो फिर तुम सिम्युलेटर के कीबोर्ड देखेंगे