-[__NSCFNumber _accessibilityViewIsVisible]: unrecognized selector sent to instance

先给懒癌晚期及其阅读恐惧症童鞋先贴下解决方法

继承于 UITableView 的class 不能定义 以下属性
//@property (nonatomic, assign) NSInteger index;

只能用
@property (nonatomic, copy) NSString *index;
或者
@property (nonatomic, assign) NSInteger currentIndex;

今天我们新版的App出现一个很诡异的bug
首页加载的时候会出现这个crash
堆栈很奇怪 定位到了main函数
而且全局断点无效

测试和开发一开始都没有找到重现路径
国内外的资料找了一天都没什么头绪
就是这时同事看到accessibility 这个单词联想到是否跟iOS系统自带的辅助功能有关
于是抖机灵的打开了 设置-通用-辅助功能-(旁白或者语音-双指下滑朗读选项)
然后在我们app首页启动辅助功能 就重现了这个crash路径和信息

就在我们以为找到了路径能解bug的时候又傻逼了
一个个界面屏蔽
排除了一个下午没排除到具体的问题
最后才定位在
一个自定义的UITableView 用

[self.view addSubView: [tableViewClass alloc] init]];

不进行任何初始化 然后调用辅助功能就会crash

于是乎用runtime把UITableView类所有成员变量打印出来
Runtime基本介绍

 unsigned int iVarCount;
    
    Ivar *iVarList = class_copyIvarList([UITableView class], &iVarCount);
    
    for (int i = 0; i < iVarCount; i++) {
        
        Ivar aVar = iVarList[i];
        
        NSLog(@"%s",ivar_getName(aVar));
    }
/*

.270772  _rowData
.270895  _rowHeight
.271007  _sectionHeaderHeight
.271166  _sectionFooterHeight
.271442  _estimatedRowHeight
.271567  _estimatedSectionHeaderHeight
.271703  _estimatedSectionFooterHeight
.271825  _visibleBounds
.271975  _subviewManager
.272076  _visibleRows
.272168  _visibleCells
.272341  _templateLayoutCells
.272469  _indexPathBeingCreated
.272635  _firstResponderIndexPath
.272918  _firstResponderView
.273159  _firstResponderViewType
.273518  _reusableTableCells
.303977  _nibMap
.304102  _nibExternalObjectsTables
.304203  _headerFooterNibMap
.304289  _headerFooterNibExternalObjectsTables
.304437  _topSeparator
.304540  _extraSeparators
.304635  _visibleHeaderViews
.304763  _visibleFooterViews
.304853  _reusableHeaderFooterViews
.304997  _highlightedIndexPaths
.305251  _selectedIndexPaths
.305517  _swipedIndexPath
.305757  _highlightedSpringLoadedIndexPath
.305988  _pendingSelectionIndexPath
.306243  _pendingDeselectionIndexPaths
.306465  _newContentView
.306702  _deleteAnimationSupport
.306981  _reorderingSupport
.307231  _backgroundView
.307460  _clearBlendingView
.307705  _wrapperView



.308015  _index



.308280  _tableHeaderBackgroundView
.308572  _tableHeaderView
.308833  _tableFooterView
.309010  _countLabel
.309535  _sectionIndexTitlesForTableView
.309802  _indexOverlayIndicatorView
.310196  _indexOverlayTimer
.310547  _indexOverlayIndicatorEventIgnoreTimer
.310699  _currentIndexTitleIndex
.310905  _indexOverlaySelectionView
.311554  _tableReloadingSuspendedCount
.311869  _sectionIndexMinimumDisplayRowCount
.312745  _updateAnimationCount
.313065  _lastFloatingSection
.314186  _insertItems
.314538  _deleteItems
.317482  _reloadItems
.318338  _moveItems
.319139  _separatorColor
.319308  _darkenedSeparatorColor
.319508  _separatorTopShadowColor
.319770  _separatorBottomShadowColor
.320000  _separatorEffect
.320275  _accessoryBaseColor
.320615  _checkmarkColor
.320829  _sectionBorderColor
.321132  _indexColor
.321425  _indexBackgroundColor
.321661  _indexTrackingBackgroundColor
.321918  _defaultSectionIndexTitles
.322157  _swipeActionController
.322353  _swipeDeletionShadowUpdateIdentifiers
.322632  _swipeGestureRecognizer
.322842  _swipeToDeleteGobblerGestureRecognizer
.323056  _swipeToDeleteCell
.323311  _updateCount
.323524  _shadowUpdateCount
.323808  _revertingShadowUpdateCount
.324104  _displayingCellContentStringIndexPath
.324302  _longPressGestureRecognizer
.324558  _upArrowLongPressGestureRecognizer
.324774  _downArrowLongPressGestureRecognizer
.325045  _upArrowTapGestureRecognizer
.325245  _downArrowTapGestureRecognizer
.325458  _longPressAutoscrollTimer
.325727  _longPressAutoscrollDirection
.326061  _sectionContentInset
.326450  _sectionBorderWidth
.326691  _sectionCornerRadius
.326956  _currentTouch
.327230  _cellClassDict
.327446  _headerFooterClassDict
.327733  _topPadding
.328026  _bottomPadding
.328300  _separatorInset
.328505  _updateCompletionHandler
.328712  _deferredEditingHandler
.328974  _hiddenSeparatorIndexPaths
.329129  _tentativeCells
.329887  _tentativeHeaderViews
.330336  _tentativeFooterViews
.330775  _clientGesturesRequiringTableGesturesToFail
.331072  _currentUpdate
.331813  _shadowUpdatesController
.332116  _preReloadVisibleRowRange
.332506  _preReloadFirstCellOffset
.332798  _lastWindow
.333015  _focusedViewType
.333177  _contentFocusContainerGuide
.333452  _constants
.333647  _targetIndexPathForScrolling
.333843  _targetOffsetToIndexPathForScrolling
.334062  _indexRetargetFeedbackGenerator
.334306  _sectionChangeFeedbackGenerator
.334557  _reorderFeedbackGenerator
.334768  _performUsingPresentationValuesCount
.334927  _prefetchDataSource
.335167  _prefetchContext
.335368  _coalescedContentSizeDelta
.335531  _tableFlags
.335816  _dragDelegate
.336066  _dropDelegate
.336295  _focusedCellIndexPath
.336487  _focusedCell
.336725  _indexPathToFocus
.336980  _dragController
.337142  _dropController
.337628  _placeholderContexts
.337862  _dragSourceDelegate
.338106  _dragDestinationDelegate
.338290  _cachedSectionIndexBarInsets
*/

发现系统UITableView其中有一个私有属性Index是String类型的 所以由于各种原因(苹果的bug) 会导致app崩溃 而且没有任何信息

找了很多资料找不到解决办法
因此和大家分享一下我们的解决方法
如果帮助到大家可以点个赞
鼓励up主继续创作
么么哒 (*  ̄3)(ε ̄ *)

你可能感兴趣的:(-[__NSCFNumber _accessibilityViewIsVisible]: unrecognized selector sent to instance)