Swift - 数组没有填充值

时间:2015-02-26 16:04:51

标签: ios uitableview swift

我正在尝试在表视图控制器中构建一个列表,并且我有正确的设置,但由于某种原因,我的模拟器在我设置我的数组的行崩溃。这不是错误,而是Thread问题。我还在学习XCode警告系统,所以我不确定这意味着什么,但我注意到Thread通知cityArray = ([String]) 0 values。有人可以帮忙吗?

import UIKit

class ListTableViewController: UITableViewController {

    var cityArray: [String] = ["Portland","San Francisco","Cupertino"]


    override func viewDidLoad() {
        super.viewDidLoad()
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
    }


    // MARK: - Table view data source
    override func numberOfSectionsInTableView(tableView: UITableView) -> Int {

        return 1

    }

    override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {

        return cityArray.count

    }


    override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCellWithIdentifier("cellIdentifier", forIndexPath: indexPath) as UITableViewCell

        cell.textLabel?.text = self.cityArray[indexPath.row]

        return cell
    }


}

更新:

线程消息的图像:

Line of issue

Sidebar

Console

2 个答案:

答案 0 :(得分:0)

试试这个

let cityArray: [NSArray] = ["Portland","San Francisco","Cupertino"] as NSArray

答案 1 :(得分:-1)

您还可以提供您收到的错误吗?这个数组在被枚举时是突变的还是什么问题?

此外,

var cityArray: [String] = ["Portland","San Francisco","Cupertino"]

可以改为

var cityArray = ["Portland", "San Francisco", "Cupertino"]

由于所有对象都属于同一类型,因此Swift的类型推断会为您解决此问题。

相关问题