Я пытаюсь показать UIPopoverPresentationController, у которого есть UIButton на панели навигации. Раньше это работало, но UIButton больше не отображается, начиная с iOS 11 (iPad). Интересно, что в моем всплывающем окне я также могу нажать другой UIViewController, и когда я вернусь из него, появится UIButton. Вот код для отображения всплывающего окна:
- (IBAction)buttonPressed:(id)sender {
PopupViewController *popupController = [self.storyboard instantiateViewControllerWithIdentifier:@"PopupController"];
UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:popupController];
navController.modalPresentationStyle = UIModalPresentationPopover;
[self presentViewController:navController animated:YES completion:nil];
UIPopoverPresentationController *popController = [popupController popoverPresentationController];
CGRect rect = self.button.frame;
CGSize size = CGSizeMake(500, 400);
popController.sourceView = self.view;
popController.sourceRect = rect;
popupController.preferredContentSize = size;
}
и вот код во всплывающем окне, чтобы показать UIButton:
- (void)viewWillAppear:(BOOL)animated
{
UIButton *rightButton = [[UIButton alloc]init];
[rightButton setTitle: @"Press me" forState:UIControlStateNormal];
[rightButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
rightButton.frame = CGRectMake(0, 0, 120, 24);
UIBarButtonItem *rightButtonItem = [[UIBarButtonItem alloc] initWithCustomView:rightButton];
UIBarButtonItem *flexible = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:self action:nil];
self.navigationItem.rightBarButtonItems = [NSArray arrayWithObjects:flexible, rightButtonItem, nil];
self.navigationController.preferredContentSize = self.preferredContentSize;
}
Кто-нибудь знает, что происходит? Почему кнопка теперь отображается сразу?