2

I have a text view on the main view controller. I have a bar button item on the view controller's navigation bar. When the app starts, I perform the following actions:

  1. Tap the text view to begin editing and to show the keyboard.
  2. Tap the bar button to show a popover view.
  3. Without dismissing the popover view, I dismiss the keyboard.
  4. Dismiss the popover view by tapping any other view on the screen.

Before iOS 11, the keyboard will NOT show up again after Step 4. However, in iOS 11, it will show up. It seems that in iOS 11, it restores the first responder after dismissing the popover view.

Here are my questions:

  1. Is it a bug, or some changes in iOS 11?
  2. If it is new, then how can I prevent the keyboard from showing after dismissing the popover view?

Also see the following videos:

For iOS 11:

https://www.dropbox.com/s/88wyv0y0idsmu5c/iOS%2011.mov?dl=0

For iOS 10.3:

https://www.dropbox.com/s/11gg6h39mcgb0fs/iOS%2010.3.mov?dl=0

Here are some codes:

#import "MainViewController.h"

@interface MainViewController ()

@property(nonatomic, retain)UITextView *textView;

@end

@implementation MainViewController

@synthesize textView = _textView;

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor orangeColor];
    self.textView = [[UITextView alloc] init];
    self.textView.translatesAutoresizingMaskIntoConstraints = NO;
    [self.view addSubview:self.textView];
    self.textView.backgroundColor = [UIColor blueColor];
    NSDictionary *dict = @{@"textView" : self.textView};
    NSArray *vCons = [NSLayoutConstraint constraintsWithVisualFormat:@"V:|-3-[textView]-3-|" options:0 metrics:nil views:dict];
    NSArray *hCons = [NSLayoutConstraint constraintsWithVisualFormat:@"H:|-3-[textView]-3-|" options:0 metrics:nil views:dict];
    [self.view addConstraints:vCons];
    [self.view addConstraints:hCons];
    // Do any additional setup after loading the view.
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
}


@end

#import "ViewController.h"
#import "MainViewController.h"

@interface ViewController ()

@property(retain,nonatomic)MainViewController *mainVC;

@end

@implementation ViewController

@synthesize mainVC = _mainVC;

- (void)viewDidLoad {
    [super viewDidLoad];
    self.mainVC = [[MainViewController alloc] init];
    UINavigationController *navigCon = [[UINavigationController alloc] initWithRootViewController:self.mainVC];
    self.mainVC.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"Button" style:UIBarButtonItemStylePlain target:self action:@selector(showPopover)];
    [self.view addSubview:navigCon.view];
}

-(void)showPopover {
    UIAlertController *alertCon = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerStyleActionSheet];

    UIAlertAction *action1 = [UIAlertAction actionWithTitle:@"Action 1" style:UIAlertActionStyleDefault handler:nil];
    UIAlertAction *action2 = [UIAlertAction actionWithTitle:@"Action 2" style:UIAlertActionStyleDefault handler:nil];
    [alertCon addAction:action1];
    [alertCon addAction:action2];
    [alertCon setModalPresentationStyle:UIModalPresentationPopover];
    UIPopoverPresentationController *popPresenter = [alertCon popoverPresentationController];
    popPresenter.barButtonItem = self.mainVC.navigationItem.rightBarButtonItem;
    [self presentViewController:alertCon animated:YES completion:nil];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
}


@end
Mark Lau
  • 147
  • 1
  • 9

1 Answers1

0

I just had this issue on iOS 11 with a swift app. Calling [textView resignFirstResponder] any time before dismissing the new controller was the only fix. [view endEditing] was not enough.

syousif
  • 76
  • 1
  • 4