Reputation: 3372
I am presenting a UIAlertController as an action sheet, with a button that should open an ActivityView when selected....
Both of these methods are in the same ViewController class... and work perfectly fine on iphone 8, iPhone Pro 11 Max, etc.. but fail when testing on iPad. (All running 13.5)
Original Failures were that popoverPresentationController did not have a sourceview or barbuttonitem set (or something like that) so I added the line:
activityViewController.popoverPresentationController.sourceView = [self view];
to the share method. This got me past that fine... So, now the IPAD does not crash with a GenericException.. but it never presents the activityView either. It just throws a bunch of constraint violations that appear to be related to the ActivityView attempting to be displayed,
[LayoutConstraints] Unable to simultaneously satisfy constraints.
Probably at least one of the constraints in the following list is one you don't want.
Try this:
(1) look at each constraint and try to figure out which you don't expect;
(2) find the code that added the unwanted constraint or constraints and fix it.
(
"<NSLayoutConstraint:0x6000000d2580 LPLinkView:0x7fda08498900.leading == UILayoutGuide:0x600001a39dc0'UIViewLayoutMarginsGuide'.leading (active)>",
"<NSLayoutConstraint:0x6000000d23f0 H:[LPLinkView:0x7fda08498900]-(59)-| (active, names: '|':_UIActivityContentTitleView:0x7fda08493b90 )>",
"<NSLayoutConstraint:0x6000000cf660 H:|-(0)-[_UIActivityContentTitleView:0x7fda08493b90] (active, names: '|':_UINavigationBarContentView:0x7fda085d5550 )>",
"<NSLayoutConstraint:0x6000000cf6b0 _UIActivityContentTitleView:0x7fda08493b90.trailing == _UINavigationBarContentView:0x7fda085d5550.trailing (active)>",
"<NSLayoutConstraint:0x6000000d08c0 'UIView-Encapsulated-Layout-Width' _UINavigationBarContentView:0x7fda085d5550.width == 0 (active)>",
"<NSLayoutConstraint:0x6000000d2260 'UIView-leftMargin-guide-constraint' H:|-(16)-[UILayoutGuide:0x600001a39dc0'UIViewLayoutMarginsGuide'](LTR) (active, names: '|':_UIActivityContentTitleView:0x7fda08493b90 )>"
)
but I have no constraints set up on this..and the complaints area about references to a navigationbar which my app does not have or use. These constraints must be coming from some default settings that are only relevant on the IPAD. Does anyone know what I need to be doing here to fix this on the IPAD? Why the hell is the default constraints related to something that I never set.. I only set the sourceView.
-(UIAlertController *)displayActionSheet
{
UIAlertController *sheet = [UIAlertController
alertControllerWithTitle:nil
message:nil
preferredStyle:UIAlertControllerStyleActionSheet];
.
.
.
UIAlertAction *share = [UIAlertAction
actionWithTitle:NSLocalizedString(@"Share with Friends", @"Share with Friends")
style:UIAlertActionStyleDefault
handler:^(UIAlertAction *action){
[self share];
}];
[sheet addAction:share];
.
.
.
[sheet popoverPresentationController].sourceView = [self view];
sheet.popoverPresentationController.permittedArrowDirections = 0;
[sheet popoverPresentationController].sourceRect = CGRectMake(view.bounds.size.width/2, view.bounds.size.height/2, 0, 0);
[self presentViewController:sheet animated:YES completion:nil];
return sheet;
}
-(void)share
{
NSString *shareString = @"a string to share";
UIImage *shareImage = [UIImage imageNamed:@"animagetoshare"];
NSURL *shareUrl = [NSURL URLWithString:@"a url to share"];
NSArray *activityItems = [NSArray arrayWithObjects:shareString, shareImage, shareUrl, nil];
UIActivityViewController *activityViewController = [[[UIActivityViewController alloc]
initWithActivityItems:activityItems applicationActivities:nil] autorelease];
activityViewController.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
activityViewController.excludedActivityTypes = @[UIActivityTypePrint,
UIActivityTypeCopyToPasteboard, UIActivityTypeAssignToContact,
UIActivityTypeSaveToCameraRoll, UIActivityTypeAddToReadingList];
activityViewController.popoverPresentationController.sourceView = [self view];
[self presentViewController:activityViewController animated:YES completion:nil];
}
Upvotes: 0
Views: 344
Reputation: 3372
Of course, I find the resolution 5 seconds after I post this:
However, this is just bizarre... why would I need to set the source rect if I set the source View... shouldn't it derive from this somehow? I am assuming the sourceRect being set is simply causing the constraints to be ignored?
Upvotes: 0