UITextFieldDelegate works on iOS 8 but not iOS 7

I have a UIViewController in which there is a UITextField, and conforms to the UITextFieldDelegate protocol. When I first built the application, iOS 7 was the last iOS, and when I selected the text box, the keyboard appeared as expected.

Next comes iOS 8 and Xcode 6. Nothing has changed in the code since I first wrote it, but now, curiously, when I select a text field on an iOS 8 device, a keyboard appears, but on an iOS 7 device it doesnโ€™t.

Why was that? Any ideas?

Here is my code:

#import "BBFeatVC.h" @interface BBFeatVC () @end @implementation BBFeatVC - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil { self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; if (self) { // Custom initialization } return self; } - (void)viewDidLoad { [super viewDidLoad]; self.featTextField.delegate = self; // Set label self.featLabel.numberOfLines = 0; // enhance keypad UIToolbar* numberToolbar = [[UIToolbar alloc]initWithFrame:CGRectMake(0, 0, 320, 50)]; numberToolbar.barStyle = UIBarStyleBlackTranslucent; numberToolbar.items = [NSArray arrayWithObjects: [[UIBarButtonItem alloc]initWithTitle:@"Cancel" style:UIBarButtonItemStyleBordered target:self action:@selector(cancelNumberPad)], [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil], [[UIBarButtonItem alloc]initWithTitle:@"Apply" style:UIBarButtonItemStyleDone target:self action:@selector(doneWithNumberPad)], nil]; [numberToolbar sizeToFit]; self.featTextField.inputAccessoryView = numberToolbar; } -(void)cancelNumberPad{ [self.featTextField resignFirstResponder]; } -(void)doneWithNumberPad{ NSString *numberFromTheKeyboard = self.featTextField.text; NSNumberFormatter *f = [[NSNumberFormatter alloc] init]; [f setNumberStyle:NSNumberFormatterDecimalStyle]; NSNumber *num = [f numberFromString:numberFromTheKeyboard]; NSInteger newStat = [num integerValue]; [[NSUserDefaults standardUserDefaults] setInteger:newStat forKey:self.featStat]; [self.featTextField resignFirstResponder]; } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } @end 
+1
source share
1 answer

Red herring, if ever. As it turned out, this was the case when iOS Simulator detected a hardware keyboard and, therefore, did not pick up the iPhone simulated keyboard. The reason I thought the delegate was running on iOS 8, not iOS 7, was because my device was running iOS 8, and so I would test on the device when I tested this version of iOS, and I used the simulator when I needed to test iOS 7 As soon as I tested iOS 8 on a simulator, I discovered my erroneous assumption, and it became clear to me that the difference was not between iOS versions, but between the device and the simulator. I fixed the problem by going to the simulator, and then in the "Hardware" menu, then "Keyboard", then uncheck the "Connect hardware keyboard" box.

It upset me to the end. I hope someone benefits from my post!

0
source

Source: https://habr.com/ru/post/1204975/


All Articles