【发布时间】:2015-10-30 13:37:47
【问题描述】:
我正在用UIAlertController 转换我所有的UIActionSheet 和UIAlertView。
我的问题是当我尝试呈现样式 ActionSheet 的UIAlertController 时。
这是我的代码:
UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"Title"
message:@"My message"
preferredStyle:UIAlertControllerStyleActionSheet];
UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:nil];
[alert addAction:cancelAction];
UIAlertAction *OKAction = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:nil];
[alert addAction:OKAction];
UIAlertAction *destroyAction = [UIAlertAction actionWithTitle:@"Destroy" style:UIAlertActionStyleDestructive handler:nil];
[alert addAction:destroyAction];
UIPopoverPresentationController *popPresenter = [alert popoverPresentationController];
popPresenter.sourceView = self.view;
popPresenter.sourceRect = self.view.bounds;
[self presentViewController:alert animated:YES completion:nil];
这是错误:
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.
(Note: If you're seeing NSAutoresizingMaskLayoutConstraints that you don't understand, refer to the documentation for the UIView property
translatesAutoresizingMaskIntoConstraints)
(
"<NSLayoutConstraint:0x7c00ab40 H:[UIView:0x7c0764c0(304)]>",
"<NSLayoutConstraint:0x7b6c7f80 _UIAlertControllerView:0x7b6c2e50'title'.width >= UIView:0x7b6c3230.width>",
"<NSLayoutConstraint:0x7ccdfe40 _UIAlertControllerView:0x7b6c2e50'title'.width == UIView:0x7b6efbe0.width>",
"<NSAutoresizingMaskLayoutConstraint:0x7c33b9d0 h=--& v=--& H:[UIView:0x7c1094e0(0)]>"
)
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x7c00ab40 H:[UIView:0x7c0764c0(304)]>
谢谢大家。
【问题讨论】:
-
该错误提示您尝试将
alert.view.translatesAutoresizingMaskIntoConstraints设置为NO。你试过这个吗? -
是的,我试过
[alert.view setTranslatesAutoresizingMaskIntoConstraints:NO];,同样的问题 -
你有没有想过这个问题?我也有同样的问题。
标签: ios objective-c iphone uiactionsheet uialertcontroller