【发布时间】:2019-08-22 10:20:58
【问题描述】:
我有一个表格视图,它显示了一系列预加载在数组中的图像,但是当我运行代码时,它会因为这个错误而崩溃“
2019-08-22 12:19:10.756047+0200 Wee'd like to help[44388:5089505]
libMobileGestalt MobileGestalt.c:890: MGIsDeviceOneOfType is not
supported on this platform.
2019-08-22 12:19:10.884482+0200 Wee'd like to help[44388:5089505] [LayoutConstraints] Unable to simultaneously satisfy constraints.
Probably at least one of the constraints in the following list is one you don't want.
Try this:
(1) look at each constraint and try to figure out which you don't expect;
(2) find the code that added the unwanted constraint or constraints and fix it.
(
"<NSLayoutConstraint:0x6000038cb890 UILayoutGuide:0x6000022d3720'UIViewSafeAreaLayoutGuide'.trailing == UIStackView:0x7fdffdc24870.trailing + 1 (active)>",
"<NSLayoutConstraint:0x6000038f7ac0 H:[UIStackView:0x7fdffdc24870]-(16)-| (active, names: '|':UIView:0x7fdffdc233d0 )>",
"<NSLayoutConstraint:0x6000038f75c0 'UIViewSafeAreaLayoutGuide-right' H:[UILayoutGuide:0x6000022d3720'UIViewSafeAreaLayoutGuide']-(0)-|(LTR) (active, names: '|':UIView:0x7fdffdc233d0 )>"
)
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x6000038cb890 UILayoutGuide:0x6000022d3720'UIViewSafeAreaLayoutGuide'.trailing == UIStackView:0x7fdffdc24870.trailing + 1 (active)>
Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints to catch this in the debugger.
The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in <UIKitCore/UIView.h> may also be helpful.
2019-08-22 12:19:12.780647+0200 Wee'd like to help[44388:5089505] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: '-[UITableViewController loadView] instantiated view controller with identifier "UIViewController-lwe-wj-C4h" from storyboard "Main", but didn't get a UITableView.'
*** First throw call stack:
(
0 CoreFoundation 0x000000010b04f1bb __exceptionPreprocess + 331
1 libobjc.A.dylib 0x000000010934a735 objc_exception_throw + 48
2 CoreFoundation 0x000000010b04f015 +[NSException raise:format:] + 197
3 UIKitCore 0x0000000112b969dc -[UITableViewController loadView] + 621
4 UIKitCore 0x0000000112ba60ee -[UIViewController loadViewIfRequired] + 175
5 UIKitCore 0x0000000112ba6940 -[UIViewController view] + 27
6 UIKitCore 0x0000000112af0a9b -[UINavigationController _startCustomTransition:] + 931
7 UIKitCore 0x0000000112b073f0 -[UINavigationController _startDeferredTransitionIfNeeded:] + 741
8 UIKitCore 0x0000000112b087e0 -[UINavigationController __viewWillLayoutSubviews] + 150
9 UIKitCore 0x0000000112ae8600 -[UILayoutContainerView layoutSubviews] + 217
10 UIKitCore 0x00000001136af795 -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 1441
11 QuartzCore 0x0000000109d9fb19 -[CALayer layoutSublayers] + 175
12 QuartzCore 0x0000000109da49d3 _ZN2CA5Layer16layout_if_neededEPNS_11TransactionE + 395
13 QuartzCore 0x0000000109d1d7ca _ZN2CA7Context18commit_transactionEPNS_11TransactionE + 342
14 QuartzCore 0x0000000109d5497e _ZN2CA11Transaction6commitEv + 576
15 QuartzCore 0x0000000109d556fa _ZN2CA11Transaction17observer_callbackEP19__CFRunLoopObservermPv + 76
16 CoreFoundation 0x000000010afb3c27 __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 23
17 CoreFoundation 0x000000010afae0be __CFRunLoopDoObservers + 430
18 CoreFoundation 0x000000010afae751 __CFRunLoopRun + 1537
19 CoreFoundation 0x000000010afade11 CFRunLoopRunSpecific + 625
20 GraphicsServices 0x000000010f5d51dd GSEventRunModal + 62
21 UIKitCore 0x00000001131c581d UIApplicationMain + 140
22 Wee'd like to help 0x00000001089f0bf7 main + 71
23 libdyld.dylib 0x000000010c4e8575 start + 1
24 ??? 0x0000000000000001 0x0 + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException"
我已经尝试重置和清除约束
这是我的 tableViewController 代码
class StrainTableViewController: UITableViewController {
var diseasePics = [UIImage()]
override func viewDidLoad() {
super.viewDidLoad()
loadPics()
// Uncomment the following line to preserve selection between presentations
// self.clearsSelectionOnViewWillAppear = false
// Uncomment the following line to display an Edit button in the navigation bar for this view controller.
// self.navigationItem.rightBarButtonItem = self.editButtonItem
}
// MARK: - Table view data source
override func numberOfSections(in tableView: UITableView) -> Int {
// #warning Incomplete implementation, return the number of sections
return 1
}
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
// #warning Incomplete implementation, return the number of rows
return diseasePics.count
}
func loadPics(){
let anxietyPic = UIImage(named: "Anxiety")
let depressionPic = UIImage(named: "Depression")
let arthritisPic = UIImage(named: "Arthritis")
let crampsPic = UIImage(named: "Cramps")
let fatiguePic = UIImage(named: "Fatigue")
let headachePic = UIImage(named: "Headache")
diseasePics = [anxietyPic,depressionPic, arthritisPic, crampsPic, fatiguePic,headachePic] as! [UIImage]
}
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "StrainCell", for: indexPath) as! StrainTableViewCell
let image = diseasePics[indexPath.row]
cell.diseaseImage.image = image
return cell
}
}
我真的不认为问题是约束,我认为这里有问题
【问题讨论】:
-
修改第二行。
-
我没有看到任何约束代码。问题必须在您的 StrainCell 布局中。尝试只显示一个单元格,并使用调试视图层次结构和控制台日志找到有问题的视图。
-
什么意思?
-
@gloria00 您能否添加调试输出中显示的错误。例如看看这个question。这将使我们能够了解导致崩溃的原因。
-
我添加了完整的错误堆栈
标签: swift uitableview uiimageview tablecell