üzerinde UITableViewController'dan moda görünümünü gösterme UIViewController
'u iPhone'dan UITableViewController
içinde bir pop-up sunumuyla gösteren bir sorun yaşıyorum. Kullandığım kod, başka bir UIViewController
'dan bir popover görüntülemek için çalışıyor, iPhone'da bir UITableViewController
değil. IPad'de UITableViewController
'dan çalışır.popoverPresentationController, iPhone
Kod yürütüldüğünde, görünüm geçici olarak (adaptivePresentationStyleForPresentationController
uygulamamış olmanız beklendiği gibi) sunulur ve sonra da bir tür Otomatik Düzen hatası oluştumuş gibi siyahla kaplanmıştır (konsolda hiçbir şey olmamasına rağmen Aksini belirtmek için).
Bahsettiğim gibi, iPhone üzerinde UITableViewController
'un dışında aşağıdakiler çalışır ve her zaman iPad'de çalışır. Eminim ki oldukça basit bir şey eksik. Herhangi bir fikir?
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
/* Create label */
UILabel *label = [UILabel new];
label.text = @"This should be in a popover.";
label.numberOfLines = 0;
label.lineBreakMode = NSLineBreakByWordWrapping;
/* Add label to new ViewController */
UIViewController *popoverVC = [UIViewController new];
[popoverVC.view addSubview:label];
label.translatesAutoresizingMaskIntoConstraints = NO;
[popoverVC.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|-[label]-|" options:0 metrics:nil views:NSDictionaryOfVariableBindings(label)]];
[popoverVC.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|-[label]-|" options:0 metrics:nil views:NSDictionaryOfVariableBindings(label)]];
/* Define ViewController to present as a popover and display */
popoverVC.modalPresentationStyle = UIModalPresentationPopover;
popoverVC.preferredContentSize = CGSizeMake(320, 50);
[self presentViewController:popoverVC animated:YES completion:nil];
/* Grab handle to ViewController's popoverPresentationController after displaying */
UIPopoverPresentationController *popoverController = [popoverVC popoverPresentationController];
if (popoverController == nil)
NSLog(@"popoverController is nil");
else {
popoverController.delegate = self;
popoverController.popoverLayoutMargins = UIEdgeInsetsMake(15, 15, 15, 15);
popoverController.sourceView = tableView;
popoverController.sourceRect = [tableView rectForRowAtIndexPath:indexPath];
self.definesPresentationContext = YES;
}
}
- (UIModalPresentationStyle)adaptivePresentationStyleForPresentationController:(UIPresentationController *)controller traitCollection:(UITraitCollection *)traitCollection
{
NSLog(@"%s", __PRETTY_FUNCTION__);
return (UIModalPresentationNone);
}
FWIW:
- (BOOL)shouldPerformSegueWithIdentifier:(NSString *)identifier sender:(id)sender
{
return (NO);
}
: Hızla bu kodu prototipini bir yolu Xcode yeni bir "Master-Detay Uygulama" şablondan
MasterViewController.m
yukarıdaki ekleyin ve
DetailViewController
iterek önlemek için bu mesajı tanımlamaktır
ayarını da UIPopoverPresentationControllerDelegate
protokolünü benimsemeye ayarlamanız gerekir.
Bu arada, popover’ın viewDidAppear: 'da [[self.view window] recursiveDescription] 'hata ayıklayıcı komutunu kullandım. – Sulthan
Bu, şu anda görünen modelin arka planının sarı görünmesini sağlar, ancak görünüm yine de kalıcıdır, bir popover değil. – greg
@greg Tamam, cevabı güncelledim. – Sulthan