UIButton をタップして遷移したいが落ちる
Q&A
Closed
解決したいこと
1. HomeHeaderViewCell
に設置したaccountButton
をタップしてMyAccountViewCotroller
へ遷移させたいのですが、アプリが落ちてしまいます。遷移の処理はHomeViewController
にデリゲートしています。理由がわからないので教えてほしいです。アプリが落ちた時のデバッグを貼っておきます。コードは長すぎて見辛くなるので、Gitからご覧いただけると幸いです。
<デバッグ>
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'NSLayoutConstraint for <UIImageView: 0x1088595a0; frame = (0 0; 0 0); userInteractionEnabled = NO; image = <(null):0x0 (null) anonymous; (0 0)@0>; layer = <CALayer: 0x6000002d7c20>>: A constraint cannot be made between a leading/trailing attribute and a right/left attribute. Use leading/trailing for both or neither.'
*** First throw call stack:
(
0 CoreFoundation 0x000000018048d8a8 __exceptionPreprocess + 172
1 libobjc.A.dylib 0x000000018008409c objc_exception_throw + 56
2 CoreAutoLayout 0x00000001ca3c4c44 ResolveConstraintArguments + 940
3 CoreAutoLayout 0x00000001ca3c4cdc +[NSLayoutConstraint constraintWithItem:attribute:relatedBy:toItem:attribute:multiplier:constant:] + 88
4 SnapKit 0x0000000106e5ef44 $sSo18NSLayoutConstraintC4item9attribute9relatedBy6toItemAD10multiplier8constantAByp_So0A9AttributeVSo0A8RelationVypSgAJ12CoreGraphics7CGFloatVAPtcfCTO + 368
5 SnapKit 0x0000000106e5eb5c $s7SnapKit10ConstraintC4from2to8relation14sourceLocation5label10multiplier8constant8priorityAcA0C4ItemC_AmA0C8RelationOSS_SutSSSgAA0C16MultiplierTarget_pAA0c8ConstantP0_pAA0c8PriorityP0_ptcfc + 4 6 SnapKit 0x0000000106e5da60 $s7SnapKit10ConstraintC4from2to8relation14sourceLocation5label10multiplier8constant8priorityAcA0C4ItemC_AmA0C8RelationOSS_SutSSSgAA0C16MultiplierTarget_pAA0c8ConstantP0_pAA0c8PriorityP0_ptcfC + 1 7 SnapKit 0x0000000106e6fd9c $s7SnapKit21ConstraintDescriptionC10constraintAA0C0CSgvgAGyXEfU_ + 592
8 SnapKit 0x0000000106e6faa4 $s7SnapKit21ConstraintDescriptionC10constraintAA0C0CSgvg + 148
9 SnapKit 0x0000000106e749f0 $s7SnapKit15ConstraintMakerC18prepareConstraints4item7closureSayAA0C0CGAA06LayoutC4Item_p_yACXEtFZ + 388
10 SnapKit 0x0000000106e74bf8 $s7SnapKit15ConstraintMakerC15makeConstraints4item7closureyAA06LayoutC4Item_p_yACXEtFZ + 104
11 SnapKit 0x0000000106e7bb88 $s7SnapKit17ConstraintViewDSLV15makeConstraintsyyyAA0C5MakerCXEF + 96
12 Ainone 0x00000001040e591c $s6Ainone17MyAccountViewCellC13setupSubViewsyyF + 2524
13 Ainone 0x00000001040e1f90 $s6Ainone17MyAccountViewCellC5style15reuseIdentifierACSo07UITabledE5StyleV_SSSgtcfc + 1700
14 Ainone 0x00000001040e21e4 $s6Ainone17MyAccountViewCellC5style15reuseIdentifierACSo07UITabledE5StyleV_SSSgtcfcTo + 160
15 UIKitCore 0x00000001854d0028 -[UITableView _dequeueReusableViewOfType:withIdentifier:] + 416
16 UIKitCore 0x00000001854d0268 -[UITableView dequeueReusableCellWithIdentifier:] + 152
17 Ainone 0x000000010413c940 $s6Ainone23MyAccountViewControllerC05tableD0_12cellForRowAtSo07UITableD4CellCSo0kD0C_10Foundation9IndexPathVtF + 172
18 Ainone 0x000000010413cb24 $s6Ainone23MyAccountViewControllerC05tableD0_12cellForRowAtSo07UITableD4CellCSo0kD0C_10Foundation9IndexPathVtFTo + 136
19 UIKitCore 0x00000001854e4fc4 -[UITableView _createPreparedCellForGlobalRow:withIndexPath:willDisplay:] + 1376
20 UIKitCore 0x00000001854b8134 -[UITableView _updateVisibleCellsForRanges:createIfNecessary:] + 560
21 UIKitCore 0x00000001854b874c -[UITableView _updateVisibleCellsNow:] + 1112
22 UIKitCore 0x00000001854d253c -[UITableView layoutSubviews] + 144
23 UIKitCore 0x00000001857cdb1c -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 1492
24 QuartzCore 0x0000000189f6fdd4 _ZN2CA5Layer16layout_if_neededEPNS_11TransactionE + 440
25 QuartzCore 0x0000000189f7ab30 _ZN2CA5Layer28layout_and_display_if_neededEPNS_11TransactionE + 124
26 QuartzCore 0x0000000189e963bc _ZN2CA7Context18commit_transactionEPNS_11TransactionEdPd + 460
27 QuartzCore 0x0000000189ec5bf0 _ZN2CA11Transaction6commitEv + 652
28 UIKitCore 0x00000001852e2ec4 _afterCACommitHandler + 80
29 CoreFoundation 0x00000001803ed648 __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 32
30 CoreFoundation 0x00000001803e804c __CFRunLoopDoObservers + 528
31 CoreFoundation 0x00000001803e8504 __CFRunLoopRun + 968
32 CoreFoundation 0x00000001803e7d28 CFRunLoopRunSpecific + 572
33 GraphicsServices 0x000000018e7cdbc0 GSEventRunModal + 160
34 UIKitCore 0x00000001852bafdc -[UIApplication _run] + 868
35 UIKitCore 0x00000001852bec54 UIApplicationMain + 124
36 UIKitCore 0x0000000184780ab8 __swift_destroy_boxed_opaque_existential_1Tm + 12244
37 Ainone 0x000000010410da64 $sSo21UIApplicationDelegateP5UIKitE4mainyyFZ + 120
38 Ainone 0x000000010410d9dc $s6Ainone11AppDelegateC5$mainyyFZ + 44
39 Ainone 0x000000010410dae0 main + 28
40 dyld 0x00000001063e9558 start_sim + 20
41 ??? 0x0000000105dd20e0 0x0 + 4393345248
42 ??? 0xd36b000000000000 0x0 + 15234270164510834688
)
libc++abi: terminating due to uncaught exception of type NSException
2. accountButton
のレイアウトをlayoutSubviews()
内に書いたのですが、角丸と画像の設定だけ反映されません。このメソッドを使うのが良くない気はしたのですが、headerLabel
のレイアウトやaccountButton
の backgroundColor は反映されているので理由がわかりません。分かる方がいらっしゃいましたらご教授ください。
override func layoutSubviews() {
self.backgroundColor = .clear
headerLabel.text = "Home"
headerLabel.font = UIFont.boldSystemFont(ofSize: 40)
headerLabel.backgroundColor = .clear
headerLabel.textAlignment = .left
accountButton.layer.cornerRadius = accountButton.frame.height / 2 //これ
accountButton.layer.masksToBounds = true
accountButton.backgroundColor = .cyan
accountButton.imageView?.contentMode = .scaleAspectFit
accountButton.imageView?.image = UIImage(systemName: "person.fill") //これ
}