iOS 9 - 缺少 UI 元素

标签 ios objective-c xcode uitableview ios9

我正在开发一个使用 UITextField 子类(我们称之为 CustomTextField)的旧应用程序,它使用 xibs/storyboards 在 iOS 8.4 中显示。但是,在 iOS 9 的三个 View 中,有两个 View 的 UI 层次结构中缺少它。

  • 成功案例:xib。没有使用过渡。
  • 第一个失败案例:UITableViewCell 子类具有通过 Storyboard连接的 CustomTextField socket 。 TableView 的 View Controller 是用 instantiateViewControllerWithIdentifier: 实例化的。它的 tableView:cellForRowAtIndexPath: 方法返回一个非零单元格,但 CustomTextField 与自定义单元格的其他元素(开关、 ImageView 和标签)一起丢失。

  • 第二个失败案例:在主视图 Controller 的 viewDidLoad 中,使用类别方法 loadInstanceFromNib 通过 xib 添加了 CustomTextField 及其父 View ,但 CustomTextField 是UI 层次结构中缺少:

    + (id)loadInstanceFromNib    
    {
       UIView *result;
    
       NSArray* elements = [[NSBundle mainBundle] loadNibNamed:NSStringFromClass([self class]) owner:nil options:nil];
    
       for (id anObject in elements) {
           if ([anObject isKindOfClass:[self class]]) {
               result = anObject;
               break;
           }
       }
    
       return result;
    }
    

我在 CustomTextField.m 中放置了几个断点。在 iOS 9 和 8.4 中,调用了 awakeFromNib。但是,willMoveToSuperview 仅在 8.4 中针对两种失败情况调用。这是 willMoveToSuperView 的回溯:

* thread #1: tid = 0xde22fd, 0x00088ca9 Shop`-[CustomTextField willMoveToSuperview:](self=0x7be75690, _cmd=0x02115c1c, newSuperview=0x7be75160) + 57 at CustomTextField.m:39, queue = 'com.apple.main-thread', stop reason = breakpoint 1.1
  * frame #0: 0x00088ca9 Shop`-[CustomTextField willMoveToSuperview:](self=0x7be75690, _cmd=0x02115c1c, newSuperview=0x7be75160) + 57 at CustomTextField.m:39
    frame #1: 0x0188be77 UIKit`-[UIView(Internal) _addSubview:positioned:relativeTo:] + 622
    frame #2: 0x0187e976 UIKit`-[UIView(Hierarchy) addSubview:] + 56
    frame #3: 0x0186d87e UIKit`-[UIView _setTraitStorageSubviews:] + 647
    frame #4: 0x010ca608 Foundation`_NSSetUsingKeyValueSetter + 115
    frame #5: 0x010ca58d Foundation`-[NSObject(NSKeyValueCoding) setValue:forKey:] + 267
    frame #6: 0x0188f13f UIKit`-[UIView(CALayerDelegate) setValue:forKey:] + 168
    frame #7: 0x01100016 Foundation`-[NSObject(NSKeyValueCoding) setValue:forKeyPath:] + 386
    frame #8: 0x01ab4d0e UIKit`-[_UIRelationshipTraitStorage applyRecordsMatchingTraitCollection:] + 1256
    frame #9: 0x01ab3a89 UIKit`-[NSObject(_UITraitStorageAccessors) _applyTraitStorageRecordsForTraitCollection:] + 202
    frame #10: 0x01871f84 UIKit`-[UIView _traitCollectionDidChangeFromOldCollection:toNewCollection:scaleDidChange:] + 62
    frame #11: 0x0187207f UIKit`-[UIView _wrappedProcessDidChangeRecursivelyFromOldTraits:toCurrentTraits:scaleDidChange:forceNotification:] + 186
    frame #12: 0x0187215e UIKit`-[UIView _wrappedProcessDidChangeRecursivelyFromOldTraits:toCurrentTraits:scaleDidChange:forceNotification:] + 409
    frame #13: 0x0187232c UIKit`__86-[UIView _processDidChangeRecursivelyFromOldTraits:toCurrentTraits:forceNotification:]_block_invoke + 69
    frame #14: 0x01f75040 UIKit`-[UIView(AdditionalLayoutSupport) _withUnsatisfiableConstraintsLoggingSuspendedIfEngineDelegateExists:] + 134
    frame #15: 0x018722df UIKit`-[UIView _processDidChangeRecursivelyFromOldTraits:toCurrentTraits:forceNotification:] + 295
    frame #16: 0x01880773 UIKit`__45-[UIView(Hierarchy) _postMovedFromSuperview:]_block_invoke + 446
    frame #17: 0x018805ad UIKit`-[UIView(Hierarchy) _postMovedFromSuperview:] + 458
    frame #18: 0x0188c41d UIKit`-[UIView(Internal) _addSubview:positioned:relativeTo:] + 2068
    frame #19: 0x0187e976 UIKit`-[UIView(Hierarchy) addSubview:] + 56
    frame #20: 0x0186d87e UIKit`-[UIView _setTraitStorageSubviews:] + 647
    frame #21: 0x010ca608 Foundation`_NSSetUsingKeyValueSetter + 115
    frame #22: 0x010ca58d Foundation`-[NSObject(NSKeyValueCoding) setValue:forKey:] + 267
    frame #23: 0x0188f13f UIKit`-[UIView(CALayerDelegate) setValue:forKey:] + 168
    frame #24: 0x01100016 Foundation`-[NSObject(NSKeyValueCoding) setValue:forKeyPath:] + 386
    frame #25: 0x01ab4d0e UIKit`-[_UIRelationshipTraitStorage applyRecordsMatchingTraitCollection:] + 1256
    frame #26: 0x01ab3a89 UIKit`-[NSObject(_UITraitStorageAccessors) _applyTraitStorageRecordsForTraitCollection:] + 202
    frame #27: 0x01871f84 UIKit`-[UIView _traitCollectionDidChangeFromOldCollection:toNewCollection:scaleDidChange:] + 62
    frame #28: 0x0187207f UIKit`-[UIView _wrappedProcessDidChangeRecursivelyFromOldTraits:toCurrentTraits:scaleDidChange:forceNotification:] + 186
    frame #29: 0x0187232c UIKit`__86-[UIView _processDidChangeRecursivelyFromOldTraits:toCurrentTraits:forceNotification:]_block_invoke + 69
    frame #30: 0x01f75040 UIKit`-[UIView(AdditionalLayoutSupport) _withUnsatisfiableConstraintsLoggingSuspendedIfEngineDelegateExists:] + 134
    frame #31: 0x018722df UIKit`-[UIView _processDidChangeRecursivelyFromOldTraits:toCurrentTraits:forceNotification:] + 295
    frame #32: 0x0188f503 UIKit`-[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 629
    frame #33: 0x02c84771 libobjc.A.dylib`-[NSObject performSelector:withObject:] + 70
    frame #34: 0x01614e47 QuartzCore`-[CALayer layoutSublayers] + 144
    frame #35: 0x01608925 QuartzCore`CA::Layer::layout_if_needed(CA::Transaction*) + 403
    frame #36: 0x016172de QuartzCore`-[CALayer(CALayerPrivate) layoutBelowIfNeeded] + 44
    frame #37: 0x01880f08 UIKit`-[UIView(Hierarchy) layoutBelowIfNeeded] + 738
    frame #38: 0x01880c11 UIKit`-[UIView(Hierarchy) layoutIfNeeded] + 83
    frame #39: 0x01998bc5 UIKit`-[UINavigationController _layoutViewController:] + 1154
    frame #40: 0x01997d41 UIKit`-[UINavigationController _layoutTopViewController] + 261
    frame #41: 0x0199559a UIKit`-[UINavigationController navigationTransitionView:didEndTransition:fromView:toView:] + 584
    frame #42: 0x01be54b4 UIKit`-[UINavigationTransitionView _notifyDelegateTransitionDidStopWithContext:] + 334
    frame #43: 0x01be57c3 UIKit`-[UINavigationTransitionView _cleanupTransition] + 713
    frame #44: 0x01be5810 UIKit`-[UINavigationTransitionView _navigationTransitionDidStop] + 55
    frame #45: 0x0186a162 UIKit`-[UIViewAnimationState sendDelegateAnimationDidStop:finished:] + 206
    frame #46: 0x0186803d UIKit`+[UIViewAnimationState popAnimationState] + 334
    frame #47: 0x018834f4 UIKit`+[UIView(Animation) commitAnimations] + 36
    frame #48: 0x01be52b3 UIKit`-[UINavigationTransitionView transition:fromView:toView:] + 2798
    frame #49: 0x01be47bc UIKit`-[UINavigationTransitionView transition:toView:] + 56
    frame #50: 0x019999b9 UIKit`-[UINavigationController _startTransition:fromViewController:toViewController:] + 3123
    frame #51: 0x01999d85 UIKit`-[UINavigationController _startDeferredTransitionIfNeeded:] + 669
    frame #52: 0x0199aa01 UIKit`-[UINavigationController __viewWillLayoutSubviews] + 57
    frame #53: 0x01b14700 UIKit`-[UILayoutContainerView layoutSubviews] + 213
    frame #54: 0x0188f52a UIKit`-[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 668
    frame #55: 0x02c84771 libobjc.A.dylib`-[NSObject performSelector:withObject:] + 70
    frame #56: 0x01614e47 QuartzCore`-[CALayer layoutSublayers] + 144
    frame #57: 0x01608925 QuartzCore`CA::Layer::layout_if_needed(CA::Transaction*) + 403
    frame #58: 0x0160877a QuartzCore`CA::Layer::layout_and_display_if_needed(CA::Transaction*) + 26
    frame #59: 0x01564c22 QuartzCore`CA::Context::commit_transaction(CA::Transaction*) + 284
    frame #60: 0x015660b5 QuartzCore`CA::Transaction::commit() + 487
    frame #61: 0x0162e84d QuartzCore`+[CATransaction flush] + 52
    frame #62: 0x017f9a66 UIKit`-[UIApplication _reportMainSceneUpdateFinished:] + 39
    frame #63: 0x017fa9d9 UIKit`-[UIApplication _runWithMainScene:transitionContext:completion:] + 3182
    frame #64: 0x018138ee UIKit`__84-[UIApplication _handleApplicationActivationWithScene:transitionContext:completion:]_block_invoke + 59
    frame #65: 0x017f8ffa UIKit`-[UIApplication workspaceDidEndTransaction:] + 155
    frame #66: 0x06ccfc9e FrontBoardServices`__37-[FBSWorkspace clientEndTransaction:]_block_invoke_2 + 71
    frame #67: 0x06ccf72f FrontBoardServices`__40-[FBSWorkspace _performDelegateCallOut:]_block_invoke + 54
    frame #68: 0x06ce1d7c FrontBoardServices`__31-[FBSSerialQueue performAsync:]_block_invoke_2 + 30
    frame #69: 0x032fe050 CoreFoundation`__CFRUNLOOP_IS_CALLING_OUT_TO_A_BLOCK__ + 16
    frame #70: 0x032f3963 CoreFoundation`__CFRunLoopDoBlocks + 195
    frame #71: 0x032f37bb CoreFoundation`__CFRunLoopRun + 2715
    frame #72: 0x032f2a5b CoreFoundation`CFRunLoopRunSpecific + 443
    frame #73: 0x032f288b CoreFoundation`CFRunLoopRunInMode + 123
    frame #74: 0x017f89b2 UIKit`-[UIApplication _run] + 571
    frame #75: 0x017fc0b6 UIKit`UIApplicationMain + 1526
    frame #76: 0x00097bba Shop`main(argc=1, argv=0xbffb45f4) + 138 at main.m:14
    frame #77: 0x03d7fac9 libdyld.dylib`start + 1

似乎 addSubview: 在 iOS 9 中从未被调用过,但为什么呢?

最佳答案

在 Storyboard 中禁用大小类可恢复所有丢失的 subview 。

https://forums.developer.apple.com/thread/14003

关于iOS 9 - 缺少 UI 元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32315704/

相关文章:

iphone - 在枚举期间中断 for 循环( Objective-C )

ios - 如何让自定义 UIView 的 subview 出现在 Document Outline 中?

javascript - 从 require.js 模块向窗口(全局范围)注册一个函数?

ios - 'NSInvalidArgumentException',原因 : 'index out of bounds for arranged subview: ...' with UIButtonBar involved

objective-c - 从沙箱中的帮助程序读取 NSUserDefaults

ios - 在设置 Controller 中启用/禁用通知

ios - 检测 UIScrollView 和 UIView 组件上的触摸事件 [放置在 UIScrollView 内]

ios - UICollectionViewCell 滚动时重叠

c++ - 在 Cocoa 中正确实现四元数计算?

ios - IB - 将项目拖动到 `scrollview` 而不重新定位?