UITableView tableHeaderView使用beginUpdates / endUpdates设置崩溃

时间:2018-02-06 03:07:06

标签: ios iphone uitableview

当我使用beginUpdates& endUpdates设置UITableView tableHeaderView时,每天都会有数十次崩溃在第259行 代码:

[self.tableView beginUpdates];
self.tableView.tableHeaderView=self.topView;
[self.tableView endUpdates];     // line 259  crash 

以下是崩溃信息:

 13 UIKit                          0x18fe43090 UIViewAlertForUnsatisfiableConstraints + 66
 14 Foundation                     0x18a0b94cc -[NSISEngine handleUnsatisfiableRowWithHead:body:usingInfeasibilityHandlingBehavior:mutuallyExclusiveConstraints:] + 464
 15 Foundation                     0x18a099df8 -[NSISEngine tryUsingArtificialVariableToAddConstraintWithMarker:rowBody:usingInfeasibilityHandlingBehavior:mutuallyExclusiveConstraints:] + 384
 16 Foundation                     0x18a0959c4 -[NSISEngine tryToAddConstraintWithMarker:expression:integralizationAdjustment:mutuallyExclusiveConstraints:] + 688
 17 Foundation                     0x18a0955cc -[NSLayoutConstraint _addLoweredExpression:toEngine:integralizationAdjustment:lastLoweredConstantWasRounded:mutuallyExclusiveConstraints:] + 284
 18 Foundation                     0x18a0931e0 -[NSLayoutConstraint _addToEngine:integralizationAdjustment:mutuallyExclusiveConstraints:] + 272
 19 UIKit                          0x18f5ee400 __57-[UIView(AdditionalLayoutSupport) _switchToLayoutEngine:]_block_invoke_2 + 396
 20 Foundation                     0x18a092d10 -[NSISEngine withBehaviors:performModifications:] + 168
 21 UIKit                          0x18f5ee20c __57-[UIView(AdditionalLayoutSupport) _switchToLayoutEngine:]_block_invoke + 564
 22 UIKit                          0x18f4eab14 -[UIView(AdditionalLayoutSupport) _switchToLayoutEngine:] + 224
 23 UIKit                          0x18f5ee338 __57-[UIView(AdditionalLayoutSupport) _switchToLayoutEngine:]_block_invoke_2 + 196
 24 Foundation                     0x18a092d10 -[NSISEngine withBehaviors:performModifications:] + 168
 25 UIKit                          0x18f5ee20c __57-[UIView(AdditionalLayoutSupport) _switchToLayoutEngine:]_block_invoke + 564
 26 UIKit                          0x18f4eab14 -[UIView(AdditionalLayoutSupport) _switchToLayoutEngine:] + 224
 27 UIKit                          0x18f62bcf0 -[UIView(AdditionalLayoutSupport) _initializeHostedLayoutEngine] + 460
 28 UIKit                          0x18f5eb334 -[UIView(AdditionalLayoutSupport) _layoutEngineCreateIfNecessary] + 64
 29 UIKit                          0x18f5eafc8 -[UIView(UIConstraintBasedLayout) _tryToAddConstraint:roundingAdjustment:mutuallyExclusiveConstraints:] + 132
 30 UIKit                          0x18f5eed28 -[UIView(UIConstraintBasedLayout) _updateContentSizeConstraints] + 872
 31 UIKit                          0x18fe3f1f8 -[UIView(AdditionalLayoutSupport) _updateSystemConstraints] + 116
 32 UIKit                          0x18f5f05a8 -[UIButton updateConstraints] + 3412
 33 UIKit                          0x18fe3de80 -[UIView(AdditionalLayoutSupport) _sendUpdateConstraintsIfNecessaryForSecondPass:] + 192
 34 UIKit                          0x18fe3e1d0 -[UIView(AdditionalLayoutSupport) _updateConstraintsIfNeededCollectingViews:forSecondPass:] + 632
 35 UIKit                          0x18fe3e158 -[UIView(AdditionalLayoutSupport) _updateConstraintsIfNeededCollectingViews:forSecondPass:] + 512
 36 UIKit                          0x18fe3e158 -[UIView(AdditionalLayoutSupport) _updateConstraintsIfNeededCollectingViews:forSecondPass:] + 512
 37 UIKit                          0x18fe3e974 __100-[UIView(AdditionalLayoutSupport) _updateConstraintsIfNeededWithViewForVariableChangeNotifications:]_block_invoke + 84
 38 UIKit                          0x18fe3db30 -[UIView(AdditionalLayoutSupport) _withUnsatisfiableConstraintsLoggingSuspendedIfEngineDelegateExists:] + 136
 39 UIKit                          0x18fe3e580 -[UIView(AdditionalLayoutSupport) _updateConstraintsIfNeededWithViewForVariableChangeNotifications:] + 164
 40 UIKit                          0x18fe3f58c -[UIView(AdditionalLayoutSupport) _updateConstraintsAtEngineLevelIfNeededWithViewForVariableChangeNotifications:] + 372
 41 UIKit                          0x18f500328 -[UIView(Hierarchy) layoutBelowIfNeeded] + 544
 42 UIKit                          0x18f4fc7dc +[UIView(Animation) performWithoutAnimation:] + 104
 43 UIKit                          0x18f821b2c __46-[UITableView _updateWithItems:updateSupport:]_block_invoke.996 + 1984
 44 UIKit                          0x18f5240f0 +[UIView(UIViewAnimationWithBlocks) _setupAnimationWithDuration:delay:view:options:factory:animations:start:animationStateGenerator:completion:] + 636

2 个答案:

答案 0 :(得分:0)

只需删除[self.tableView beginUpdates];[self.tableView endUpdates];

即可

答案 1 :(得分:0)

如何在self.topView上设置约束?看看堆栈跟踪,似乎系统无法满足所有约束。我会查看topView并确保所有约束都有效。