आईओएस 5.1 और आईओएस 5.0 में यह काम करता है, लेकिन आईओएस 6.0 में कीबोर्ड नहीं दिखता है।आईओएस 6 में, - [यूआईटीएक्स्टफिल्ड बन गया फर्स्ट रेस्पॉन्डर] -व्यू में काम नहीं करता है WillAppear:
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
UITextField *textField = self.emailAddressTextField;
[textField becomeFirstResponder];
}
अब के लिए मैंने तर्क -viewDidAppear:
पर ले जाया है।
// This works but is not desirable.
- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
UITextField *textField = self.emailAddressTextField;
[textField becomeFirstResponder];
}
यह काम करता है, लेकिन वांछनीय नहीं है। कीबोर्ड लोड-अप एनीमेशन दृश्य लोड के बाद दिखाया गया है।
मैं कुंजीपटल के रूप में उपस्थित होना चाहता हूं क्योंकि स्लाइड-टू-बाएं एनीमेशन नेविगेशन नियंत्रक में दृश्य को लोड किया गया है।
क्या किसी को पता है कि आईओएस 6 में दृश्य के रूप में कीबोर्ड लोड कैसे किया जाए?
अद्यतन
@ बतख की प्रतिक्रिया के आधार पर, मैं एक छोटे से अधिक परीक्षण किया था। यह UITextViewCells में निहित UITextFields के लिए विशिष्ट प्रतीत होता है।
क्या किसी के पास कोई सुझाव है?
पहला समाधान
तो पूरा विवरण। यह दो स्थिर सेल (ईमेल और पासवर्ड) के साथ एक टेबल दृश्य है। एक दृश्य में एक लॉगिन बटन है जिसे टेबल फ़ूटर व्यू असाइन किया गया है। दोनों कोशिकाओं में उनमें एक टेक्स्ट फ़ील्ड है और एक कस्टम प्रकार SICOTextFieldCell हैं।
मेरा समाधान लॉगिन बटन (टेबल फ़ूटर व्यू में) के पीछे नकली टेक्स्ट फ़ील्ड रखना था।
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
UITextField *textField = self.SICO_fakeTextField;
[textField becomeFirstResponder];
}
- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
UITextField *textField = self.SICO_emailAddressTextField;
[textField becomeFirstResponder];
}
नए समाधान
@stm द्वारा जवाब के आधार पर, मैं एक नया (बेहतर?) समाधान के साथ आया था।
मेरा समाधान -selectRowAtIndexPath:animated:scrollPosition:
पर कॉल करना था। -[SICOTextFieldCell setSelected:animated:]
, जो एक कस्टम टेबल व्यू सेल है, [self.textField becomeFirstResponder]
पर कॉल करता है जो कीबोर्ड को सही तरीके से खींचता है। यह अभी भी एक हैक है, लेकिन यह एक क्लीनर हैक है।
@interface SICOLogInViewController()
@property (readonly, nonatomic) UITextField *SICO_emailAddressTextField;
@property (readonly, nonatomic) UITextField *SICO_passwordTextField;
@end
@implementation SICOLogInViewController
- (IBAction)logIn
{
// Controller Details
}
#pragma mark Private
- (UITextField *)SICO_textFieldForRowAtIndexPath:(NSIndexPath *)indexPath
{
SICOTextFieldCell *cell = (SICOTextFieldCell *)[self.tableView cellForRowAtIndexPath:indexPath];
return cell.textField;
}
#pragma mark View lifecycle
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
[self.tableView selectRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0]
animated:NO scrollPosition:UITableViewScrollPositionTop];
}
#pragma mark UITextFieldDelegate
- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
switch (textField.returnKeyType) {
case UIReturnKeyGo: [self logIn]; break;
case UIReturnKeyNext: [self.SICO_passwordTextField becomeFirstResponder]; break;
default: break;
}
return YES;
}
#pragma mark Properties
- (UITextField *)SICO_emailAddressTextField
{
return [self SICO_textFieldForRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0]];
}
- (UITextField *)SICO_passwordTextField
{
return [self SICO_textFieldForRowAtIndexPath:[NSIndexPath indexPathForRow:1 inSection:0]];
}
@end
आप 'viewWillAppear' में उस कोड को रखने की कोशिश की? –
@yulz हां, मेरा मूल कोड '-viewWillAppear:' में था। –
आपके कोड में इसे फेंकने में कुछ और है, यह ठीक चलना चाहिए। यदि आप एक त्वरित फिक्स चाहते हैं, तो [textField प्रदर्शन चयनकर्ता: @ चयनकर्ता (बनें फर्स्ट रेस्पोन्डर) के साथ कॉल करें: nil afterDelay: 0.1f]; [टेक्स्टफिल्ड बनने के बजाय फर्स्ट रेस्पॉन्डर]; यह बाद में पहला उत्तरदाता 1/10 सेट करेगा, संभावित रूप से जो भी समस्याग्रस्त कोड दे रहा है, आपके पास दौड़ने के लिए समय हो सकता है और इसे बाद में 1/10 के बाद नहीं रोक सकता है। यह एक बेवकूफ कामकाज है, हालांकि आदर्श समाधान नहीं है। – Anton