我正在尝试在方法prepareForSegue中设置标签的文本组件,但是当执行该方法时应用程序崩溃,我查看了其他讨论,但没有一个帮助过我,我正在编程在最新版本的xCode中迅速移植并构建到iPhone上。 当我删除将标签文本设置为"用餐名称"的行时,不会发生崩溃。 断点位于设置标签文本的行上。 如果有人能帮助我,那就太棒了,谢谢。
- 编辑 -
FirstViewController的 prepareForSegue
代码:
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
let dest : SecondViewController = segue.destinationViewController as! SecondViewController
dest.mealNameLabel.text = "Meal Name"
}
完整堆栈跟踪:( - >中断)
libswiftCore.dylib`function signature specialization <Arg[0] = Exploded, Arg[1] = Exploded, Arg[2] = Dead, Arg[3] = Dead> of Swift._fatalErrorMessage (Swift.StaticString, Swift.StaticString, Swift.StaticString, Swift.UInt) -> ():
0x1001de55c <+0>: stp x29, x30, [sp, #-16]!
0x1001de560 <+4>: mov x29, sp
0x1001de564 <+8>: sub sp, sp, #16 ; =16
0x1001de568 <+12>: and w8, w2, #0x1
0x1001de56c <+16>: tbnz w8, #0, 0x1001de58c ; <+48>
0x1001de570 <+20>: tbnz x1, #63, 0x1001de5c8 ; <+108>
0x1001de574 <+24>: add x1, x0, x1
0x1001de578 <+28>: mov x2, x3
0x1001de57c <+32>: mov x3, x4
0x1001de580 <+36>: mov x4, x5
0x1001de584 <+40>: bl 0x1002265b0 ; function signature specialization <Arg[0] = Exploded, Arg[1] = Exploded> of Swift.(_fatalErrorMessage (Swift.StaticString, Swift.StaticString, Swift.StaticString, Swift.UInt) -> ()).(closure #2)
-> 0x1001de588 <+44>: brk #0x1
0x1001de58c <+48>: str xzr, [sp, #8]
0x1001de590 <+52>: cmp x0, w0, uxtw
0x1001de594 <+56>: b.ne 0x1001de6e0 ; <+388>
0x1001de598 <+60>: lsr w8, w0, #11
0x1001de59c <+64>: cmp w8, #26 ; =26
0x1001de5a0 <+68>: b.hi 0x1001de5ec ; <+144>
0x1001de5a4 <+72>: cmp w0, #128 ; =128
0x1001de5a8 <+76>: b.lo 0x1001de630 ; <+212>
0x1001de5ac <+80>: cmp w0, #2048 ; =2048
0x1001de5b0 <+84>: b.hs 0x1001de660 ; <+260>
0x1001de5b4 <+88>: movz x8, #0
0x1001de5b8 <+92>: movz x10, #0
0x1001de5bc <+96>: lsr w9, w0, #6
0x1001de5c0 <+100>: orr w9, w9, #0xffffffc0
0x1001de5c4 <+104>: b 0x1001de694 ; <+312>
0x1001de5c8 <+108>: adr x0, #723338 ; "fatal error"
0x1001de5cc <+112>: nop
0x1001de5d0 <+116>: adr x3, #723840 ; "UnsafeBufferPointer with negative count"
0x1001de5d4 <+120>: nop
0x1001de5d8 <+124>: movz w1, #0xb
0x1001de5dc <+128>: orr w2, wzr, #0x2
0x1001de5e0 <+132>: movz w4, #0x27
0x1001de5e4 <+136>: orr w5, wzr, #0x2
0x1001de5e8 <+140>: bl 0x1001de55c ; <+0>
0x1001de5ec <+144>: cmp w0, #14, lsl #12 ; =57344
0x1001de5f0 <+148>: b.lo 0x1001de63c ; <+224>
0x1001de5f4 <+152>: cmp w0, #272, lsl #12 ; =1114112
0x1001de5f8 <+156>: b.hs 0x1001de738 ; <+476>
0x1001de5fc <+160>: lsr w8, w0, #6
0x1001de600 <+164>: lsr w9, w0, #16
0x1001de604 <+168>: cbz w9, 0x1001de664 ; <+264>
0x1001de608 <+172>: lsr w9, w0, #18
0x1001de60c <+176>: orr w9, w9, #0xf0
0x1001de610 <+180>: cmp w9, w9, uxtb
0x1001de614 <+184>: b.ne 0x1001de6e0 ; <+388>
0x1001de618 <+188>: orr w10, wzr, #0xffffff80
0x1001de61c <+192>: bfxil w10, w0, #12, #6
0x1001de620 <+196>: and x12, x9, #0xff
0x1001de624 <+200>: str x12, [sp, #8]
0x1001de628 <+204>: orr w11, wzr, #0x1
0x1001de62c <+208>: b 0x1001de674 ; <+280>
0x1001de630 <+212>: movz x8, #0
0x1001de634 <+216>: movz x9, #0
0x1001de638 <+220>: b 0x1001de6d0 ; <+372>
0x1001de63c <+224>: adr x0, #723222 ; "fatal error"
0x1001de640 <+228>: nop
0x1001de644 <+232>: adr x3, #726652 ; "high- and low-surrogate code points are not valid Unicode scalar values"
0x1001de648 <+236>: nop
0x1001de64c <+240>: movz w1, #0xb
0x1001de650 <+244>: orr w2, wzr, #0x2
0x1001de654 <+248>: movz w4, #0x47
0x1001de658 <+252>: orr w5, wzr, #0x2
0x1001de65c <+256>: bl 0x1001de55c ; <+0>
0x1001de660 <+260>: lsr w8, w0, #6
0x1001de664 <+264>: lsr w9, w0, #12
0x1001de668 <+268>: movz x11, #0
0x1001de66c <+272>: movz x12, #0
0x1001de670 <+276>: orr w10, w9, #0xffffffe0
0x1001de674 <+280>: lsl x13, x11, #3
0x1001de678 <+284>: orr w9, wzr, #0xffffff80
0x1001de67c <+288>: bfxil w9, w8, #0, #6
0x1001de680 <+292>: and w8, w10, #0xff
0x1001de684 <+296>: lsl x8, x8, x13
0x1001de688 <+300>: orr x10, x8, x12
0x1001de68c <+304>: str x10, [sp, #8]
0x1001de690 <+308>: add x8, x11, #1 ; =1
0x1001de694 <+312>: orr w11, wzr, #0x8
0x1001de698 <+316>: umulh x11, x8, x11
0x1001de69c <+320>: cmp xzr, x11
0x1001de6a0 <+324>: b.ne 0x1001de6e0 ; <+388>
0x1001de6a4 <+328>: lsl x11, x8, #3
0x1001de6a8 <+332>: cmp x11, #63 ; =63
0x1001de6ac <+336>: b.hi 0x1001de714 ; <+440>
0x1001de6b0 <+340>: orr w12, wzr, #0x80
0x1001de6b4 <+344>: bfxil x12, x0, #0, #6
0x1001de6b8 <+348>: and w9, w9, #0xff
0x1001de6bc <+352>: lsl x9, x9, x11
0x1001de6c0 <+356>: orr x9, x9, x10
0x1001de6c4 <+360>: str x9, [sp, #8]
0x1001de6c8 <+364>: add x8, x8, #1 ; =1
0x1001de6cc <+368>: mov x0, x12
0x1001de6d0 <+372>: orr w10, wzr, #0x8
0x1001de6d4 <+376>: umulh x10, x8, x10
0x1001de6d8 <+380>: cmp xzr, x10
0x1001de6dc <+384>: b.eq 0x1001de6e4 ; <+392>
0x1001de6e0 <+388>: brk #0x1
0x1001de6e4 <+392>: lsl x10, x8, #3
0x1001de6e8 <+396>: cmp x10, #64 ; =64
0x1001de6ec <+400>: b.hs 0x1001de714 ; <+440>
0x1001de6f0 <+404>: and x11, x0, #0xff
0x1001de6f4 <+408>: lsl x10, x11, x10
0x1001de6f8 <+412>: orr x9, x10, x9
0x1001de6fc <+416>: str x9, [sp, #8]
0x1001de700 <+420>: add x9, sp, #8 ; =8
0x1001de704 <+424>: add x8, x8, x9
0x1001de708 <+428>: add x1, x8, #1 ; =1
0x1001de70c <+432>: add x0, sp, #8 ; =8
0x1001de710 <+436>: b 0x1001de578 ; <+28>
0x1001de714 <+440>: adr x0, #723006 ; "fatal error"
0x1001de718 <+444>: nop
0x1001de71c <+448>: adr x3, #723412 ; "shift amount is larger than type size in bits"
0x1001de720 <+452>: nop
0x1001de724 <+456>: movz w1, #0xb
0x1001de728 <+460>: orr w2, wzr, #0x2
0x1001de72c <+464>: movz w4, #0x2d
0x1001de730 <+468>: orr w5, wzr, #0x2
0x1001de734 <+472>: bl 0x1001de55c ; <+0>
0x1001de738 <+476>: adr x0, #722970 ; "fatal error"
0x1001de73c <+480>: nop
0x1001de740 <+484>: adr x3, #726480 ; "value is outside of Unicode codespace"
0x1001de744 <+488>: nop
0x1001de748 <+492>: movz w1, #0xb
0x1001de74c <+496>: orr w2, wzr, #0x2
0x1001de750 <+500>: movz w4, #0x25
0x1001de754 <+504>: orr w5, wzr, #0x2
0x1001de758 <+508>: bl 0x1001de55c ; <+0>
这是我使用dest访问的视图控制器的代码: (感谢Emptyless)
//
// SecondViewController.swift
// FoodTracker
//
// Created by Michael Buerger on 7/4/16.
// Copyright © 2016 Michael Buerger. All rights reserved.
//
import UIKit
class SecondViewController: UIViewController {
// MARK: Properties
@IBOutlet weak var mealNameLabel: UILabel!
var mealName: String?
override func viewDidLoad() {
super.viewDidLoad()
if mealName != nil {
mealNameLabel.text = mealName
}
}
}
答案 0 :(得分:3)
最有可能的问题是您正在访问尚未初始化的IBOutlet。如果不是直接设置UITextLabel
而是创建一个包含文本的变量,那么您可能会更幸运:
作为SecondViewController的属性:
var labelText : String?
在FirstViewController的prepareForSegue()
中:
des.labelText = "Your Text"
并在SeconViewController的viewDidLoad()
中:
self.MeatNameLabel.text = labelText