UITraitCollection getter,iOS13不支持

我正在尝试为iOS13更新我的项目。我在应用程序项目中使用UIScrollSlidingPages库。

我将这个库放在我的UIViewController中,如下所示。我将自定义视图放在数据源中。

- (TTSlidingPage *)pageForSlidingPagesViewController:(TTScrollSlidingPagesController_Custom*)source atIndex:(int)index{

    PhotoGalleryItemView *item = [[PhotoGalleryItemView alloc] initPhotoGalleryItem:[restaurantData.Galeri objectAtIndex:index] ParentViewController:self];
    item.view.frame = _ViewPhotoContainer.frame;
    TTSlidingPage *slidingPage = [[TTSlidingPage alloc] initWithContentViewController:item];

    return slidingPage;
}

但是,当我运行该应用程序时,尽管我使用DispatchQueue Main Async like these solutions重新加载数据,它仍然崩溃。

2019-11-08 09:42:22.760428+0300 GastroClub[5790:35896] WARNING: GoogleAnalytics 3.17 void GAIUncaughtExceptionHandler(NSException *) (GAIUncaughtExceptionHandler.m:48): Uncaught exception: <PhotoGalleryItemView: 0x7f9eb1782db0> returned nil from -traitCollection,which is not allowed.
2019-11-08 09:42:22.925971+0300 GastroClub[5790:35896] invalid mode 'kCFRunLoopCommonmodes' provided to CFRunLoopRunSpecific - break on _CFRunLoopError_RunCalledWithInvalidmode to debug. This message will only appear once per execution.
2019-11-08 09:42:22.988883+0300 GastroClub[5790:35896] *** Assertion failure in UITraitCollection * _Nonnull _UIgetcurrentFallbackTraitCollection(void)(),/BuildRoot/library/Caches/com.apple.xbs/Sources/UIKitCore_Sim/UIKit-3900.12.15/_UIFallbackEnvironment.m:91
2019-11-08 09:42:22.990119+0300 GastroClub[5790:35896] *** WebKit discarded an uncaught exception in the webView:didFinishLoadForFrame: delegate: <NSInternalInconsistencyException> <PhotoGalleryItemView: 0x7f9eb1782db0> returned nil from -traitCollection,which is not allowed.
2019-11-08 09:42:27.776557+0300 GastroClub[5790:35896] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException',reason: '<PhotoGalleryItemView: 0x7f9eb1782db0> returned nil from -traitCollection,which is not allowed.'
*** First throw call stack:
(
    0   CoreFoundation                      0x00007fff23c4f02e __exceptionPreprocess + 350
    1   libobjc.A.dylib                     0x00007fff50b97b20 objc_exception_throw + 48
    2   CoreFoundation                      0x00007fff23c4eda8 +[NSException raise:format:arguments:] + 88
    3   Foundation                          0x00007fff256c9c2a -[NSAssertionHandler handleFailureInFunction:file:lineNumber:description:] + 166
    4   UIKitCore                           0x00007fff474abd67 _UIgetcurrentFallbackTraitCollection + 962
    5   UIKitCore                           0x00007fff47d00909 UIViewCommonInitWithFrame + 644
    6   UIKitCore                           0x00007fff47d00647 -[UIView initWithFrame:] + 98
    7   UIKitCore                           0x00007fff47cde48f -[UIImageView initWithFrame:] + 62
    8   UIKitCore                           0x00007fff47cffe99 -[UIView init] + 44
    9   GastroClub                          0x000000010816d313 -[UIImageView(Preloader) addPreloder] + 131
    10  GastroClub                          0x000000010816dcf6 -[UIImageView(Preloader) setImageWithURL_ShowPreloader:placeholderImage:options:progress:completed:] + 182
    11  GastroClub                          0x000000010816db69 -[UIImageView(Preloader) setImageWithURL_ShowPreloader:] + 105
    12  GastroClub                          0x00000001080c29f8 -[PhotoGalleryItemView viewDidLoad] + 200
    13  UIKitCore                           0x00007fff471cdb45 -[UIViewController _sendViewDidLoadWithAppearanceProxyObjectTaggingEnabled] + 83
    14  UIKitCore                           0x00007fff471d2a9e -[UIViewController loadViewIfRequired] + 1084
    15  UIKitCore                           0x00007fff471d2ebb -[UIViewController view] + 27
    16  UIScrollSlidingPages                0x000000010a06f2fd -[TTSlidingPage setContentViewController:] + 93
    17  UIScrollSlidingPages                0x000000010a06f18b -[TTSlidingPage initWithContentViewController:] + 139
    18  GastroClub                          0x000000010806b32d -[RestaurantDetailViewController pageForSlidingPagesViewController:atIndex:] + 429
    19  UIScrollSlidingPages                0x000000010a06b6cf -[TTScrollSlidingPagesController reloadPages] + 3455
    20  GastroClub                          0x0000000108060d42 __48-[RestaurantDetailViewController addPhotoSlider]_block_invoke + 50
    21  libdispatch.dylib                   0x000000010abc6dd4 _dispatch_call_block_and_release + 12
    22  libdispatch.dylib                   0x000000010abc7d48 _dispatch_client_callout + 8
    23  libdispatch.dylib                   0x000000010abd5de6 _dispatch_main_queue_callback_4CF + 1500
    24  CoreFoundation                      0x00007fff23bb1df9 __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 9
    25  CoreFoundation                      0x00007fff23baca59 __CFRunLoopRun + 2329
    26  CoreFoundation                      0x00007fff23babe16 CFRunLoopRunSpecific + 438
    27  GraphicsServices                    0x00007fff38438bb0 GSEventRunmodal + 65
    28  UIKitCore                           0x00007fff4784fb68 UIApplicationmain + 1621
    29  GastroClub                          0x000000010801b900 main + 112
    30  libdyld.dylib                       0x00007fff51a1dc25 start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException

然后我尝试使用this solution修复该问题。我将这种方法放在我的自定义视图中,如下所示:

@interface PhotoGalleryItemView (){

    GCGaleri *galleryItem;

}

@property (weak,nonatomic) IBOutlet UIImageView *IMGViewGallery;
@end

@implementation PhotoGalleryItemView

- (id)initPhotoGalleryItem:(GCGaleri*)GalleryItem ParentViewController :(RestaurantDetailViewController*)ParentViewController {

    if (self) {
        galleryItem = GalleryItem;
    }
    return self;
}

- (void)viewDidLoad {
    [super viewDidLoad];

    [_IMGViewGallery setImageWithURL_ShowPreloader:[NSURL URLWithString:galleryItem.Foto]];

    _IMGViewGallery.clipsToBounds = YES;
    _IMGViewGallery.contentMode = UIViewContentModeScaleAspectFill;

}
// I put here
- (UITraitCollection *)traitCollection
{
    if (@available(iOS 13.0,*)) {
        [UITraitCollection setCurrentTraitCollection:[[UITraitCollection alloc]init]];
    } else {
        // Fallback on earlier versions
    };
    return [[UITraitCollection alloc]init];
}

@end

在那之后,我运行我的应用程序,它因以下错误而崩溃:

2019-11-08 10:03:40.570894+0300 GastroClub[5914:42170] [TraitCollection] Class PhotoGalleryItemView overrides the -traitCollection getter,which is not supported. If you're trying to override traits,you must use the appropriate API.
2019-11-08 10:03:40.571987+0300 GastroClub[5914:42170] [Assert] Current fallback trait collection contains one or more unspecified traits: {(
    "_UITraitNameDisplayGamut","_UITraitNameDebugHighlight","_UITraitNameDisplayScale","_UITraitNameDisplayCornerRadius","_UITraitNamePresentationSemanticContext","_UITraitNameUserInterfaceLevel","_UITraitNameVibrancy","_UITraitNameLegibilityWeight","_UITraitNamePreferredContentSizeCategory","_UITraitNameaccessibilityContrast","_UITraitNameTouchLevel","_UITraitNameSemanticContext"
)}; traitCollection: <UITraitCollection: 0x600001984600; >; currentFallbackEnvironment: <PhotoGalleryItemView: 0x7fdeb1e9cac0>

我该如何解决该问题?我无法更新我的库,因为它不再处于活动开发中。

yzhwyf 回答:UITraitCollection getter,iOS13不支持

我找到了解决方案。 slidingPage启动时,我会显示一个预加载器。显示预载程序时发生了崩溃。当我将预加载器放在DispatchAsyncAfter中时,如下所示,我可以修复错误:

dispatch_after(dispatch_time(DISPATCH_TIME_NOW,0.5 * NSEC_PER_SEC),dispatch_get_main_queue(),^{
     [self addPreloder];

        __weak typeof(self) weakSelf = self;
        [self sd_setImageWithURL:url
                placeholderImage:placeholder
                         options:options
                        progress:progressBlock
                       completed:^(UIImage *image,NSError *error,SDImageCacheType cacheType,NSURL *imageUrl) {
                           if (completedBlock) {
                               completedBlock(image,error,cacheType,imageUrl);
                           }

                           dispatch_async(dispatch_get_main_queue(),^(void) {

                               if (weakSelf.preloding) {

                                   dispatch_async(dispatch_get_main_queue(),^(void) {
                                       [weakSelf.preloding stopAnimating];
                                       [weakSelf.preloding removeFromSuperview];
                                       [weakSelf removeActivityIndicator];
                                   });

                               }

                           });
                       }
         ];
    });
,

迅速5对我有用

DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + Double(0.5 * Double(NSEC_PER_SEC)) / Double(NSEC_PER_SEC),execute: {

    // your code here

 })
本文链接:https://www.f2er.com/3139692.html

大家都在问