简体   繁体   中英

Updating ObjC app on XCode 9

I recently updated our ObjC app on XCode 9. Everything was ok (I even updated to iPhone X new layout), there has been just an issue in one of the viewControllers (built in IB). This viewController, which shows a tableView with news, can be accessed from 2 sources:

  1. From appDelegate if a Push Notification informs about new news. In this case, a right navBarButton is unhidden so the user can dismiss the view
  2. From a specific section, where a normal back button is used

When I try to open the viewController from the second case, the app crashes with the next message:

2017-10-17 12:53:26.747396-0500 verifica[17299:1270771] * Assertion failure in -[_UIButtonBarButtonVisualProviderIOS _addConstraintsForBackgroundImageWithOffset:isBackButton:], /BuildRoot/Library/Caches/com.apple.xbs/Sources/UIKit_Sim/UIKit-3694.4.18/_UIButtonBarButtonVisualProviderIOS.m:485 2017-10-17 12:53:26.855489-0500 verifica[17299:1270771] * Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: '_UIButtonBarButtonVisualProviderIOS cannot have a background without any content' *** First throw call stack: ( 0 CoreFoundation 0x000000010ba151cb exceptionPreprocess + 171 1 libobjc.A.dylib 0x000000010af48f41 objc_exception_throw + 48 2 CoreFoundation 0x000000010ba1a362 +[NSException raise:format:arguments:] + 98 3 Foundation 0x0000000106a22089 -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] + 193 4 UIKit 0x000000010860cd92 -[_UIButtonBarButtonVisualProviderIOS _addConstraintsForBackgroundImageWithOffset:isBackButton:] + 1 079 5 UIKit 0x000000010860c903 -[_UIButtonBarButtonVisualProviderIOS _configureBackgroundForButton:fromBarButtonItem:isBackButton:] + 1060 6 UIKit 0x0000000108610610 -[_UIButtonBarButtonVisualProviderIOS configureButton:fromBarButtonItem:] + 2630 7 UIKit 0x000000010860dcaf -[_UIButtonBarButtonVisualProviderIOS configureButton:withAppearanceDelegate:fromBarItem:] + 148 8 UIKit 0x0000000107ff3096 -[_UIButtonBarButton _configureFromBarItem:appearanceDelegate:isBackButton:] + 86 9 UIKit 0x0000000107ff2c20 -[_UIButtonBarButton configureFromBarItem:withAppearanceDelegate:] + 53 10 UIKit 0x00000001085a2049 -[_UIButtonBar _updatedViewForBarButtonItem:withView:] + 338 11 UIKit 0x00000001085a0add __32-[_UIButtonBar _newGroupLayout:]_block_invoke + 82 12 UIKit 0x00000001085960d3 -[_UIButtonBarItemLayout _updateItemView] + 53 13 UIKit 0x000000010859667c -[_UIButtonBarItemLayout _configure] + 40 14 UIKit 0x000000010859518f -[_UIButtonBarLayout configure] + 60 15 UIKit 0x00000001085952d9 -[_UIButton BarLayout addLayoutViews:] + 49 16 UIKit 0x000000010859864e -[_UIButtonBarItemGroupLayout _iterateConfiguredLayouts:] + 228 17 UIKit 0x000000010859872f -[_UIButtonBarItemGroupLayout _addLayoutViews:] + 116 18 UIKit 0x000000010859523d -[_UIButtonBarLayout addLayoutViews:layoutGuides:constraintsToActivate:constraintsToDeactivate:] + 111 19 UIKit 0x00000001085a1264 -[_UIButtonBar _layoutBar] + 1833 20 UIKit 0x00000001085a3b44 -[_UIButtonBarStackView updateConstraints] + 48 21 UIKit 0x000000010870d8b6 -[UIView(AdditionalLayoutSupport) _sendUpdateConstraintsIfNecessaryForSecondPass:] + 161 22 UIKit 0x000000010870ded2 -[UIView(AdditionalLayoutSupport) _updateConstraintsIfNeededCollectingViews:forSecondPass:] + 1296 23 UIKit 0x000000010870dd51 -[UIView(AdditionalLayoutSupport) _updateConstraintsIfNeededCollectingViews:forSecondPass:] + 911 24 Foundation 0x00000001069acde1 -[NSISEngine withBehaviors:performModifications:] + 131 25 UIKit 0x000000010870e703 __100-[UIView(AdditionalLayoutSupport) _updateConstraintsIfNeededWithViewForVariableChangeNotifications:]_block_invoke + 90 26 UIKit 0x000000010870cf61 -[UIView(AdditionalLayoutSupport) _withUnsatisfiableConstraintsLoggingSuspendedIfEngineDelegateExists:] + 104 27 UIKit 0x000000010870e272 -[UIView(AdditionalLayoutSupport) _updateConstraintsIfNeededWithViewForVariableChangeNotifications:] + 160 28 UIKit 0x000000010870f38c -[UIView(AdditionalLayoutSupport) _updateConstraintsAtEngineLevelIfNeededWithViewForVariableChangeNotifications:] + 401 29 UIKit 0x0000000107c671b6 -[UIView(Hierarchy) layoutBelowIfNeeded] + 1517 30 UIKit 0x00000001084a74cd -[_UINavigationBarTransitionContextPush _prepareContentView] + 130 31 UIKit 0x00000001084a8b2b -[_UINavigationBarTransitionContextPush prepare] + 133 32 UIKit 0x000000010878d15a -[_UINavigationBarVisualProviderModernIOS _performAnimationWithTransitionCompletion:transition:] + 740 33 UIKit 0x0000000107cb60b6 -[UINavigationBar _pushNavigationItem:transitionAssistant:] + 359 34 UIKit 0x000 0000107cb58e2 -[UINavigationBar _pushNavigationItemUsingCurrentTransition:] + 368 35 UIKit 0x0000000107cb5a47 -[UINavigationBar pushNavigationItem:animated:] + 179 36 UIKit 0x0000000107cb02cf -[UINavigationBar _performUpdatesIgnoringLock:] + 47 37 UIKit 0x0000000107cb5b51 -[UINavigationBar _pushNavigationItem:transition:] + 152 38 UIKit 0x0000000107d97f37 __71-[UINavigationController pushViewController:transition:forceImmediate:]_block_invoke + 371 39 UIKit 0x0000000107d9812c __71-[UINavigationController pushViewController:transition:forceImmediate:]_block_invoke.1981 + 114 40 UIKit 0x0000000107d92bcf __98-[UINavigationController _shouldSkipHostedRefreshControlUpdateSchedulingDeferredUpdateIfNecessary]_block_invoke + 18 41 UIKit 0x0000000107d94b25 -[UINavigationController _startDeferredTransitionIfNeeded:] + 1343 42 UIKit 0x0000000107d95b90 -[UINavigationController __viewWillLayoutSubviews] + 115 43 UIKit 0x0000000107fec2ae -[UILayoutContainerView layoutSubviews] + 231 44 UIKit 0x00000 00128bc4a9f -[UILayoutContainerViewAccessibility layoutSubviews] + 42 45 UIKit 0x0000000107c7c551 -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 1331 46 QuartzCore 0x000000010773a4ba -[CALayer layoutSublayers] + 153 47 QuartzCore 0x000000010773e5a9 _ZN2CA5Layer16layout_if_neededEPNS_11TransactionE + 401 48 QuartzCore 0x00000001076c71cd _ZN2CA7Context18commit_transactionEPNS_11TransactionE + 365 49 QuartzCore 0x00000001076f2ae4 _ZN2CA11Transaction6commitEv + 500 50 UIKit 0x0000000107bd8687 _afterCACommitHandler + 272 51 CoreFoundation 0x000000010b9b7db7 __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION + 23 52 CoreFoundation 0x000000010b9b7d0e __CFRunLoopDoObservers + 430 53 CoreFoundation 0x000000010b99c324 __CFRunLoopRun + 1572 54 CoreFoundation 0x000000010b99ba89 CFRunLoopRunSpecific + 409 55 GraphicsServices 0x000000010f3fd9c6 GSEventRunModal + 62 56 UIKit 0x0000000107badd30 UIApplicationMain + 159 57 verifica 0x0000000103ce9f0f main + 111 58 libdyld.dylib 0x00000001 0ac32d81 start + 1 ) libc++abi.dylib: terminating with uncaught exception of type NSException

The app worked fine before XCode 9. I've run it in the simulator (with iOS, 10.3, 10.3.1 & 11) and on an iPhone with iOS 11, and crashes all the time for case 2.

I've searched several of the terms referred in the console, but the only similar was http://www.cocoachina.com/bbs/read.php?tid-1726269.html , I used Google Translate and one guy says: "mainly due to the navigantionBarItem picture and the location of the text caused by the offset".

As I said the view was built in IB with a normal Navigation Controller, no offset in the button. The only difference with other similar viewControllers that work fine is the right navBarButton that is shown in case 1 but not in case 2 with the next code in viewDidLoad:

if (self.fromAppDelegate) {
        self.doneButton.title = @"Cerrar";
        self.doneButton.enabled = YES;
    } else self.doneButton.enabled = NO;

I'm sure its gonna be an easy solution but right now I can't find it. I hope someone can help me.

OK, when I was checking the configuration for the button in IB, I noticed that its width (Size Inspector) was zero. I changed it to 80 so, the button shows now in the preview. I also, in Attributes Inspector, changed it from Custom system item to Done and in code added the next line for the else statement:

self.doneButton.title = @"";

It worked, the app didn't crash anymore, but the button, if not enabled, was visible as Done all the time which is not what I want (the code above didn't work because it was set as System Button, duh). So, I change it back to Custom and delete the default title aaaand... everything was as before (check image in the question), but the app still works. What? Well, not everything was as before: the code above was the only change. If I commented the line, the app crashes again.

I don't know if it's a bug or a new requirement, but I hope it useful for someone (I knew the answer was gonna be easy).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM