UIActionSheet iOS 8错误
我正试图从UIActionSheet iOS 8错误,ios,cocoa-touch,ios8,uiactionsheet,nslayoutconstraint,Ios,Cocoa Touch,Ios8,Uiactionsheet,Nslayoutconstraint,我正试图从UITableViewCell上的按钮在iPad上显示UIActionSheet。它在iOS 7上工作正常,但在iOS 8上工作不正常UIActionSheet包含一些可视工件,我在控制台中收到以下警告: Unable to simultaneously satisfy constraints. Probably at least one of the constraints in the following list is one you don't want
UITableViewCell
上的按钮在iPad上显示UIActionSheet
。它在iOS 7上工作正常,但在iOS 8上工作不正常<代码>UIActionSheet包含一些可视工件,我在控制台中收到以下警告:
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:0x79793de0 H:[UIView:0x797a7630(304)]>",
"<NSLayoutConstraint:0x7a16ae00 UIView:0x7a16ab60.width == _UIAlertControllerView:0x797a9230.width>",
"<NSAutoresizingMaskLayoutConstraint:0x7a66f2a0 h=--& v=--& H:[UIView:0x7a16ab60(298)]>",
"<NSLayoutConstraint:0x797a49e0 _UIAlertControllerView:0x797a9230.width >= UIView:0x797a7630.width>"
)
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x79793de0 H:[UIView:0x797a7630(304)]>
Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints to catch this in the debugger.
The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in <UIKit/UIView.h> may also be helpful.
UIActionSheet
已弃用,因此您可以使用iOS 8.0或更高版本中提供的UIAlertViewController
- (IBAction)onFavoriteBtn:(id)sender {
CGPoint btnPosition = [sender convertPoint:CGPointZero toView:self.tableView];
NSIndexPath *indexPath = [self.tableView indexPathForRowAtPoint:btnPosition];
if (indexPath) {
[self showActionSheet:sender];
}
}
- (void)showActionSheet:(UIView *)sender
{
NSString *alertTitle = NSLocalizedString(@"ActionTitle", @"Archive or Delete Data");
NSString *alertMessage = NSLocalizedString(@"ActionMessage", @"Deleted data cannot be undone");
UIAlertController *alertController = [UIAlertController alertControllerWithTitle:alertTitle
message:alertMessage
preferredStyle:UIAlertControllerStyleActionSheet];
UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"Cancel", @"Cancel action")
style:UIAlertActionStyleCancel
handler:^(UIAlertAction *action)
{
NSLog(@"Cancel action");
}];
UIAlertAction *deleteAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"Delete", @"Delete action")
style:UIAlertActionStyleDestructive
handler:^(UIAlertAction *action)
{
NSLog(@"Delete action");
}];
UIAlertAction *archiveAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"Archive", @"Archive action")
style:UIAlertActionStyleDefault
handler:^(UIAlertAction *action)
{
NSLog(@"Archive action");
}];
[alertController addAction:cancelAction];
[alertController addAction:deleteAction];
[alertController addAction:archiveAction];
UIPopoverPresentationController *popover = alertController.popoverPresentationController;
if (popover)
{
popover.sourceView = sender;
popover.sourceRect = sender.bounds;
popover.permittedArrowDirections = UIPopoverArrowDirectionAny;
}
[self presentViewController:alertController animated:YES completion:nil];
}
看起来您最喜欢的按钮superview太小,无法嵌入操作表。尝试使用窗口显示操作表,但不要忘记“转换收藏夹坐标”按钮:
- (void)onFavoriteBtn:(id)sender {
CGPoint btnPosition = [sender convertPoint:CGPointZero toView:_tableView];
NSIndexPath *indexPath = [_tableView indexPathForRowAtPoint:btnPosition];
if (indexPath) {
UIButton *favoriteBtn = (UIButton *)sender;
CGRect frame = [self.window convertRect:favoriteBtn.bounds fromView:favoriteBtn];
UIActionSheet *sheet = [[UIActionSheet alloc] initWithTitle:nil delegate:nil cancelButtonTitle:@"Cancel" destructiveButtonTitle:@"Remove from Favorites" otherButtonTitles:nil];
[sheet showFromRect:frame inView:self.window animated:true];
}
}
您建议根据iOS版本在运行时决定是使用UIActionSheet还是使用UIAlertController?@user1561346完全是。
UIAlertController
在控制台中具有相同的外观错误和警告。真的没想到。:/当然,我已经添加了alertController.popoverPresentationController.sourceRect
和alertController.popoverPresentationController.sourceView
。我在我的终端尝试了相同的代码,一切都正常。检查你的故事板可能有一些约束问题。我不认为视图必须足够大才能容纳它。它只是用来找一个位置。但我尝试将frame转换为self.view和self.navigationController.view。
- (void)onFavoriteBtn:(id)sender {
CGPoint btnPosition = [sender convertPoint:CGPointZero toView:_tableView];
NSIndexPath *indexPath = [_tableView indexPathForRowAtPoint:btnPosition];
if (indexPath) {
UIButton *favoriteBtn = (UIButton *)sender;
CGRect frame = [self.window convertRect:favoriteBtn.bounds fromView:favoriteBtn];
UIActionSheet *sheet = [[UIActionSheet alloc] initWithTitle:nil delegate:nil cancelButtonTitle:@"Cancel" destructiveButtonTitle:@"Remove from Favorites" otherButtonTitles:nil];
[sheet showFromRect:frame inView:self.window animated:true];
}
}