小编Rob*_*Rob的帖子

Swift:预期声明错误将"Label"设置为字符串变量

我在一个小的单一窗格应用程序中管理不同的语言,为每个注释使用不同的字符串数组,由整数变量"userLang"索引,然后设置label.text = array [index].基本代码是:

import UIKit
class ViewController: UIViewController {
   var userLang = 0
   var arrayOne = ["hi", "hola"]
   var arrayTwo = ["Bye", "Adios"]
   @IBOutlet weak var msgArrayOne: UILabel!
   @IBOutlet weak var msgArrayTwo: UILabel!

   msgArrayOne.text = arrayOne[userLang]  //Error here: !Expected declaration
   msgArrayTwo.text = arrayTwo[userLang]  //odd, but this line gets no error until I 
                                          //remove the first line above, then 
                                          //this line gets the same error.

   override func viewDidLoad() {
    super.viewDidLoad()
    // Do any additional setup after loading the view, typically …
Run Code Online (Sandbox Code Playgroud)

string labels swift

8
推荐指数
1
解决办法
3万
查看次数

标签 统计

labels ×1

string ×1

swift ×1