ios - UITraitCollection getter,iOS13 不支持

标签 ios swift xcode

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

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

- (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 来解决这个问题。我将此方法放在我的自定义 View 中,如下所示:

@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>

我该如何解决这个问题?我无法更新我的库,因为它不再处于积极开发状态。

最佳答案

我找到了解决方案。当我 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];
                                   });

                               }

                           });
                       }
         ];
    });

关于ios - UITraitCollection getter,iOS13 不支持,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58761971/

相关文章:

ios - 如何从命令行构建钛应用程序并调用模拟器?

ios - iOS 12.2 上的 Progressive Web App 卡在离线页面

swift - 无法将类型 '[String : Date]' 的值转换为预期的参数类型 '[FileAttributeKey : Any]?'

ios - 使用 Alamofire.upload 时出现段错误 : 11,

ios - 使用百分比填充 UIView

ios - 如何使 UITabbar 透明以便 superview 的背景图像可见?

ios - 如何复制 Xcode 项目以创建免费应用程序的付费版本

ios - 将设备 token 从 viewDidLoad 发送到 webView Objective C

iphone - 如何手动设置连接超时?

iphone - iOS初学者:字符串串联