2014-04-03 11 views
12

कीबोर्ड शॉर्टकट सुझाव को UITextField से निकालने का कोई आसान तरीका है?UITextField कीबोर्ड शॉर्टकट सुझावों को अक्षम करें

टाइपिंग सुधार को हटाने के लिए संभव है: [textField setAutocorrectionType:UITextAutocorrectionTypeNo]; हालांकि यह शॉर्टकट पर कोई प्रभाव नहीं है।

साझामेनू कंट्रोलर को प्रभावित करने से यह भी स्क्वैश नहीं होता है।

- (BOOL)canPerformAction:(SEL)action withSender:(id)sender { 
    [UIMenuController sharedMenuController].menuVisible = NO; 
    return NO; 
} 

enter image description here

उत्तर

2

एक UITextFieldDelegate विधि को लागू करने और मैन्युअल UITextField के पाठ संपत्ति सेट करके ऐसा हल।

सिम्युलेटर में डिफ़ॉल्ट रूप से आप टाइप करके इस व्यवहार परीक्षण कर सकते हैं "OMW"सुझाव देने चाहिए जो "मेरे रास्ते में!"। निम्नलिखित कोड इसे अवरुद्ध कर देगा। नोट: यह ऑटो-सुधार और भी वर्तनी की जांच करता है जो मेरे मामले में ठीक था।

- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string { 
    // Pass through backspace and character input 
    if (range.length > 0 && [string isEqualToString:@""]) { 
     textField.text = [textField.text substringToIndex:textField.text.length-1]; 
    } else { 
     textField.text = [textField.text stringByAppendingString:string]; 
    } 
    // Return NO to override default UITextField behaviors 
    return NO; 
} 
0
UITextField* f = [[UITextField alloc] init]; 
f.autocorrectionType = UITextAutocorrectionTypeNo; 
3

उपयोग यह केवल

textField.autocorrectionType = UITextAutocorrectionTypeNo; 
0

ऊपर उल्लेख जवाब कटौती/कॉपी/पेस्ट स्थिति के साथ काम नहीं कर सकते हैं। उदाहरण के लिए UITextField में टेक्स्ट काटने और पेस्ट करने पर, परिणाम डिफ़ॉल्ट कार्यक्षमता के अनुसार नहीं है।

-(BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string{ 

NSString *textFieldNewText = [textField.text stringByReplacingCharactersInRange:range withString:string]; 

    if ([string isEqualToString:@""]) { 
     // return when something is being cut 
     return YES; 
    } 
    else 
    { 
     //set text field text 
     textField.text=textFieldNewText; 
     range.location=range.location+[string length]; 
     range.length=0; 
     [self selectTextInTextField:textField range:range]; 
    } 
    return NO; 
} 


//for handling cursor position when setting textfield text through code 
- (void)selectTextInTextField:(UITextField *)textField range:(NSRange)range { 

    UITextPosition *from = [textField positionFromPosition:[textField beginningOfDocument] offset:range.location]; 
    UITextPosition *to = [textField positionFromPosition:from offset:range.length]; 
    [textField setSelectedTextRange:[textField textRangeFromPosition:from toPosition:to]]; 
} 
0

उपयोग AutocorrectionType:

नीचे एक समान दृष्टिकोण है

[mailTextField setAutocorrectionType: UITextAutocorrectionTypeNo];

1

स्विफ्ट 3.x या इसके बाद के संस्करण:

textField.autocorrectionType = .no 
संबंधित मुद्दे