xcode 13 - objc project

hi, i try to test my obj project that works in xcode 12 now with xcode13 open a popover view show me this serius bug... is it a compiler problem with beta o will be an issue of my app?

 *** Assertion failure in UITraitCollection *UIViewControllerMissingInitialTraitCollection(UIViewController *__strong)(), UIViewController.m:2298
2021-06-09 09:48:26.881216+0200 simulatore[13360:233848] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'UIViewController is missing its initial trait collection populated during initialization. This is a serious bug, likely caused by accessing properties or methods on the view controller before calling a UIViewController initializer. View controller: <PopupLogin: 0x7fb705d08560>'
*** First throw call stack:
(
	0   CoreFoundation                      0x00007fff203f6fa7 __exceptionPreprocess + 242
	1   libobjc.A.dylib                     0x00007fff2019cbe7 objc_exception_throw + 48
	2   Foundation                          0x00007fff207480dd -[NSMutableDictionary(NSMutableDictionary) classForCoder] + 0
	3   UIKitCore                           0x00007fff24778f13 UIViewControllerMissingInitialTraitCollection + 188
	4   UIKitCore                           0x00007fff2477d3d7 -[UIViewController traitCollection] + 155
	5   UIKitCore                           0x00007fff24646a88 -[UIPopoverPresentationController traitCollectionDidChange:] + 105
	6   UIKitCore                           0x00007fff24657fc0 -[UIPresentationController _updateTraitsIfNecessary] + 280
	7   UIKitCore                           0x00007fff24658377 -[UIPresentationController _setInternalOverrideTraitCollection:] + 211
	8   UIKitCore                           0x00007fff24644d79 -[UIPopoverPresentationController initWithPresentedViewController:presentingViewController:] + 739
	9   UIKitCore                           0x00007fff2479332b -[UIViewController popoverPresentationController:] + 325
	10  UIKitCore                           0x00007fff246e371a -[UIPopoverController _presentShimmedPopoverFromRect:inView:permittedArrowDirections:animated:] + 104
	11  UIKitCore                           0x00007fff246e3ab1 -[UIPopoverController presentPopoverFromRect:inView:permittedArrowDirections:animated:] + 416
	12  simulatore                          0x000000010d505848 -[iOrmaBeautyViewController bAccedi:] + 8408
	13  UIKitCore                           0x00007fff24f358e8 -[UIApplication sendAction:to:from:forEvent:] + 83
	14  UIKitCore                           0x00007fff247d844d -[UIControl sendAction:to:forEvent:] + 110
	15  UIKitCore                           0x00007fff247d882f -[UIControl _sendActionsForEvents:withEvent:] + 332
	16  UIKitCore                           0x00007fff247d70e0 -[UIControl touchesEnded:withEvent:] + 488
	17  UIKitCore                           0x00007fff24f7565a -[UIWindow _sendTouchesForEvent:] + 1287
	18  UIKitCore                           0x00007fff24f774a5 -[UIWindow sendEvent:] + 4728
	19  UIKitCore                           0x00007fff24f4eac6 -[UIApplication sendEvent:] + 595
	20  UIKitCore                           0x00007fff24fe4204 __processEventQueue + 14104
	21  UIKitCore                           0x00007fff24fdbda6 __eventFetcherSourceCallback + 240
	22  CoreFoundation                      0x00007fff20363bdc __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
	23  CoreFoundation                      0x00007fff20363ad4 __CFRunLoopDoSource0 + 180
	24  CoreFoundation                      0x00007fff20362faf __CFRunLoopDoSources0 + 242
	25  CoreFoundation                      0x00007fff2035d6f7 __CFRunLoopRun + 875
	26  CoreFoundation                      0x00007fff2035cea9 CFRunLoopRunSpecific + 567
	27  GraphicsServices                    0x00007fff2c951cd3 GSEventRunModal + 139
	28  UIKitCore                           0x00007fff24f2f72a -[UIApplication _run] + 915
	29  UIKitCore                           0x00007fff24f34192 UIApplicationMain + 101
	30  simulatore                          0x000000010dc69298 main + 104
	31  dyld                                0x000000010ee50e1e start_sim + 10
	32  ???                                 0x0000000000000001 0x0 + 1
)
libc++abi: terminating with uncaught exception of type NSException
dyld4 config: DYLD_ROOT_PATH=/Applications/Xcode-beta.app/Contents/Developer/Platforms/iPhoneOS.platform/Library/Developer/CoreSimulator/Profiles/Runtimes/iOS.simruntime/Contents/Resources/RuntimeRoot DYLD_LIBRARY_PATH=/Users/Simone/Library/Developer/Xcode/DerivedData/vanigliaprobeta-fwvkaycrayourfceorpockhodfjg/Build/Products/Debug-iphonesimulator:/Applications/Xcode-beta.app/Contents/Developer/Platforms/iPhoneOS.platform/Library/Developer/CoreSimulator/Profiles/Runtimes/iOS.simruntime/Contents/Resources/RuntimeRoot/usr/lib/system/introspection DYLD_INSERT_LIBRARIES=/Applications/Xcode-beta.app/Contents/Developer/Platforms/iPhoneOS.platform/Library/Developer/CoreSimulator/Profiles/Runtimes/iOS.simruntime/Contents/Resources/RuntimeRoot/usr/lib/libBacktraceRecording.dylib:/Applications/Xcode-beta.app/Contents/Developer/Platforms/iPhoneOS.platform/Library/Developer/CoreSimulator/Profiles/Runtimes/iOS.simruntime/Contents/Resources/RuntimeRoot/usr/lib/libMainThreadChecker.dylib:/Applications/Xcode-beta.app/Contents/Developer/Platforms/iPhoneOS.platform/Library/Developer/CoreSimulator/Profiles/Runtimes/iOS.simruntime/Contents/Resources/RuntimeRoot/Developer/Library/PrivateFrameworks/DTDDISupport.framework/libViewDebuggerSupport.dylib:/Applications/Xcode-beta.app/Contents/Developer/Platforms/iPhoneOS.platform/Library/Developer/CoreSimulator/Profiles/Runtimes/iOS.simruntime/Contents/Resources/RuntimeRoot/usr/lib/libMTLCapture.dylib DYLD_FRAMEWORK_PATH=/Users/Simone/Library/Developer/Xcode/DerivedData/vanigliaprobeta-fwvkaycrayourfceorpockhodfjg/Build/Products/Debug-iphonesimulator
*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'UIViewController is missing its initial trait collection populated during initialization. This is a serious bug, likely caused by accessing properties or methods on the view controller before calling a UIViewController initializer. View controller: <PopupLogin: 0x7fb705d08560>'
terminating with uncaught exception of type NSException
CoreSimulator 772.1 - Device: iPad Pro (12.9-inch) (5th generation) (5B9B2A53-699B-4F05-AF9C-40F4495DE42A) - Runtime: iOS 15.0 (19A5261u) - DeviceType: iPad Pro (12.9-inch) (5th generation)
(lldb) 
code-block

Replies

The assertion is stating effectively that your app is trying to access a property on UIViewController before you've run an -init method. Given where the assertion is taking place, it would seem most likely that you have a case where you are failing to call any -init method.

Can you post the code where you create the PopupLogin view controller?

            PopupLogin *comuni =[PopupLogin alloc];
            popover=[[UIPopoverController alloc] initWithContentViewController:comuni];


            if ([mainDelegate.aListdb count]>0)
            {
                [comuni.BtnDB setHidden:NO];
            }
            else
            {
                [comuni.BtnDB setHidden:YES];
            }


            popover.delegate = self;
            popover.popoverContentSize = CGSizeMake(550, 260);
            comuni._popover=popover;


            CGRect rect = CGRectMake((self.view.frame.size.width-550)/2, (self.view.frame.size.height-307)/2, 550, 307);
            [popover presentPopoverFromRect:rect inView:self.view permittedArrowDirections:0 animated:YES];
  • PopupLogin *comuni =[PopupLogin alloc]; That is your bug, you are never calling an initializer on the PopupLogin instance after alloc.

Add a Comment

i just solved with this:


- (UITraitCollection *)traitCollection {
    if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) {
        return super.traitCollection;
    } else {
        switch (self.modalPresentationStyle) {
            case UIModalPresentationFormSheet:
            case UIModalPresentationPopover:
                return [UITraitCollection traitCollectionWithHorizontalSizeClass:UIUserInterfaceSizeClassCompact];

            default:
                return super.traitCollection;
        }
    }
}

- (UITraitCollection *)overrideTraitCollectionForChildViewController:(UIViewController *)childViewController
{
    UIDevice *device = [UIDevice currentDevice];

    if (device.userInterfaceIdiom == UIUserInterfaceIdiomPhone && CGRectGetWidth(childViewController.view.bounds) > CGRectGetHeight(childViewController.view.bounds)) {
        return [UITraitCollection traitCollectionWithHorizontalSizeClass:UIUserInterfaceSizeClassRegular];
    }

    return nil;
}