iOS   发布时间:2022-03-30  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了ipad – iOS8beta中的UIActionSheet崩溃大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我有一些代码,只需点击按钮即可显示UIActionSheet.
但是当我在iPad中使用XCode5.1 iOS8beta构建它时会崩溃.

下面是我用来显示UIActionSheet的代码.

UIActionSheet *tmpActionSheet = [[UIActionSheet alloc] initWithtitle:nil
                                                                delegate:self
                                                       cancelButtontitle:@"Cancel"
                                                  destructiveButtontitle:nil
                                                       otherButtontitles:
                                     @"Ok",nil];
    [tmpActionSheet showInView:self.view];

注意:
– 完美适用于XCode6beta iOS8beta(iPhone / iPad)
– 完美适用于XCode5.1 iOS8beta(仅限iPhonE)

异常的日志记录如下.

2014-06-23 15:54:04.860 ActionSheetDemo[680:191598] 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:0x14e60ef0 V:|-(0)-[UIView:0x14d419a0]   (Names: '|':UIView:0x14d3a8b0 )>","<NSLayoutConsTraint:0x14e60880 _UIDimmingKnockoutBACkdropView:0x14d2ca80.top == UIView:0x14d419a0.top>","<NSLayoutConsTraint:0x14e61600 V:[_UIDimmingKnockoutBACkdropView:0x14d2ca80(>=44)]>","<NSLayoutConsTraint:0x14e66240 _UIDimmingKnockoutBACkdropView:0x14d2ca80.bottom ==>"
)

Will attempt to recover by breaking consTraint 
<NSLayoutConsTraint:0x14e66240 _UIDimmingKnockoutBACkdropView:0x14d2ca80.bottom ==>

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.
2014-06-23 15:54:04.872 ActionSheetDemo[680:191598] 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,"<NSLayoutConsTraint:0x14d25f80 _UIDimmingKnockoutBACkdropView:0x14d2ca80.bottom ==>"
)

Will attempt to recover by breaking consTraint 
<NSLayoutConsTraint:0x14d25f80 _UIDimmingKnockoutBACkdropView:0x14d2ca80.bottom ==>

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.
2014-06-23 15:54:04.878 ActionSheetDemo[680:191598] 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,"<NSLayoutConsTraint:0x14e67740 _UIDimmingKnockoutBACkdropView:0x14d2ca80.bottom ==>"
)

Will attempt to recover by breaking consTraint 
<NSLayoutConsTraint:0x14e67740 _UIDimmingKnockoutBACkdropView:0x14d2ca80.bottom ==>

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.
2014-06-23 15:54:04.885 ActionSheetDemo[680:191598] 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,"<NSLayoutConsTraint:0x14d38a30 _UIDimmingKnockoutBACkdropView:0x14d2ca80.bottom ==>"
)

Will attempt to recover by breaking consTraint 
<NSLayoutConsTraint:0x14d38a30 _UIDimmingKnockoutBACkdropView:0x14d2ca80.bottom ==>

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.
2014-06-23 15:54:04.892 ActionSheetDemo[680:191598] *** TerminaTing app due to uncaught exception 'NSInvalidArgumentexception',reason: 'Application tried to present modally an active controller <_UIAlertShimPresenTingViewController: 0x14d450c0>.'
*** First throw call stack:
(0x24702c2f 0x315cdd1f 0x27ffa6e7 0x27df9799 0x2838f3bd 0x2838e94d 0x6bfdd 0x27d4a6c7 0x27d4a669 0x27d34a4d 0x27d4a099 0x27d49d73 0x27d42ff1 0x27d198b1 0x27f8f13d 0x27d183c1 0x246ca597 0x246c99ab 0x246c8029 0x246145a1 0x246143b3 0x2b8cc1b9 0x27d78c41 0x6c239 0x31b67aaf)
libc++abi.dylib: terminaTing with uncaught exception of type NSException

题 :
1]为什么我的应用程序崩溃?
2]是iOS8beta的bug吗?

补丁直到苹果解决了这个问题
为UIActionSheet类创建Objective-C分类

代码

#define SYstem_VERSION_EQUAL_TO(v)                  ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSorderedSamE)
#define SYstem_VERSION_GREATER_THAN(v)              ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSorderedDescending)
#define SYstem_VERSION_GREATER_THAN_OR_EQUAL_TO(v)  ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSorderedAscending)
#define SYstem_VERSION_LESS_THAN(v)                 ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSorderedAscending)
#define SYstem_VERSION_LESS_THAN_OR_EQUAL_TO(v)     ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSorderedDescending)

@implementation UIActionSheet (simplyShowInViewAddition)

- (void) simplyShowInView:(UIView *) view
{
    if(SYstem_VERSION_LESS_THAN(@"8.0"))
    {
        [self showInView:view];
    }
    else
    {
        // "TranslaTing" UIActionSheet to UIAlertController for better compatibility with iOS 8
        UIAlertController *alert = [UIAlertController alertControllerWithtitle:nil message:self.title preferredStyle:UIAlertControllerStyleActionSheet];
        int nactions = [self numberOfButtons];
        int i=0;
        while(i<nactions)
        {
            NSString *button_title=[self buttontitleATindex:i];
            UIAlertActionStyle style=UIAlertActionStyleDefault;
            if(i==[self cancelButtonIndex])
            {
                style = UIAlertActionStyleCancel;
            }
            else if(i==[self destructiveButtonIndex])
            {
                style = UIAlertActionStyleDestructive;
            }

            UIAlertAction *newAction = [UIAlertAction actionWithtitle:button_title style:style handler:^(UIAlertAction *action) {
                NSLog(@"clicked action %d",i);
                [self.delegate actionSheet:self clickedButtonATindex:i];
            }];

            [alert addAction:newAction];
            i++;
        }

        if (UI_user_iNTERFACE_I@L_134_25@m() == UIUserInterfaceI@L_134_25@mPad)
        {
            [alert setModalPresentationStyle:UIModalPresentationPopover];

            UIPopoverPresentationController *popPresenter = [alert
                                                             popoverPresentationController];
            popPresenter.sourceView = view;
            popPresenter.sourceRect = CGRectMake(view.frame.size.width/2-1,0.45*view.frame.size.height,2,1);
            popPresenter.permittedArrowDirections = 0;
        }
        UIViewController *sourceViewController;
        if(self.delegate!=nil && [self.delegate respondsToSELEctor:@SELEctor(presentViewController:animated:completion:)])
        {
            NSLog(@"presenTing UIAlertController on source view controller");
            sourceViewController=(UIViewController *)(self.delegatE);
        }
        else
        {
            // When the actionsheet delegate is not a UIViewController
            NSLog(@"presenTing UIAlertController on displayed view controller");
            sourceViewController = /* Set up a method here to obtain the view controller where you want to display it */
        }
        [sourceViewController presentViewController:alert animated:YES completion:nil];
    }
}

link

解决方法

我也有同样的问题.我使用ShowFromBarButtonItem函数而不是ShowInView函数.

[organizeActionSheet showFromBarButtonItem:btnAction animated:NO];

如果使用ShowFromRect或showFromBarButtonItem运行时异常将不会到来.
我认为这是IOS8 Beta的一个错误,当我使用ShowInView运行时异常即将到来.

这个错误在IOS Beta 4中没有发生..

当使用Xcode 5.1构建时,我在调试窗口中收到一些警告消息,但确实出现了操作表.在iOS 8 beta 4中,它显示为视图外侧的小弹出窗口(侧面),而在iOS 7中,它曾经显示为从视图底部向上滑动的按钮.

大佬总结

以上是大佬教程为你收集整理的ipad – iOS8beta中的UIActionSheet崩溃全部内容,希望文章能够帮你解决ipad – iOS8beta中的UIActionSheet崩溃所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。