我想在迅速循环,但我有问题

发布于 2025-02-09 19:52:14 字数 538 浏览 2 评论 0原文

我尝试了循环,但是为什么只显示检查的循环?和测试,tick不会出现

override func viewDidLoad()
      {
        super.viewDidLoad()
        doSomething()
        label()
      }
        
        @IBOutlet weak var subTitle: UILabel!
        
        let text = ["test", "check", "checked"]
        
        func label(){
            for name in text {
                print(subTitle.text = (name))
            }
        }

I tried loop but why does it only show checked ones? and test, the tick does not appear

override func viewDidLoad()
      {
        super.viewDidLoad()
        doSomething()
        label()
      }
        
        @IBOutlet weak var subTitle: UILabel!
        
        let text = ["test", "check", "checked"]
        
        func label(){
            for name in text {
                print(subTitle.text = (name))
            }
        }

enter image description here

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

冷血 2025-02-16 19:52:14

您的代码和问题都没有意义。

您的label()函数中的打印语句甚至不应编译:

print(subTitle.text = (name))

该怎么办?打印语句将将输出记录到调试控制台。但是,express subtitle.text =(name)看起来不像合法的swift。您是否试图判断标签字段的内容是否包含数组中的一个字符串?如果是这样,您需要使用==(比较)不是=(分配。)

尝试:

print("label text = \(name) ==", subTitle.text == (name))

Neither your code nor your question make much sense.

The print statement in your label() function should not even compile:

print(subTitle.text = (name))

What is that supposed to do? The print statement will log output to the debug console. however, the expression subTitle.text = (name) does not look like legal swift. Are you trying to tell if the contents of your label field contains one of the strings in your array? If so, you need to use == (comparison) not = (assignment.)

Try:

print("label text = \(name) ==", subTitle.text == (name))
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文