Swift,如何将tableview数据传递给视图控制器?

时间:2015-11-13 00:16:59

标签: ios swift viewcontroller

我希望能够将数据文件位置传递给我的其他视图控制器。我能够通过它,但它只在视图控制器上显示时显示一个文件位置。我从儿子那里得到多个,所有的细胞都回到最后一个。我怎样才能解决这个问题? 继承我的代码:

if let filelocation = fileList["urllocation"] as? String
{
    TableData1.append(filelocation)
    fileLocationLabelString = (filelocation)
}

override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
    selectedFileLocation = fileLocationLabelString

    if(segue.identifier == "detailView") {    
        let vc = segue.destinationViewController as! DisplayWorkViewController
        vc.selectedFileLocation = selectedFileLocation
        vc.selectedLabel = selectedLabel
        print("selectedFileLocation = \(vc.selectedFileLocation)")
    }
}

1 个答案:

答案 0 :(得分:0)

TableData1是数组变量,fileLocationLabelString只是一个String。为了获得完整的位置列表,您必须传递TableData1而不是fileLocationLabelString

编辑:

DisplayWorkViewController

var listLocation: Array<String> = [""]

当前视图控制器

if let filelocation = fileList["urllocation"] as? String
{
    TableData1.append(filelocation)
    fileLocationLabelString = (filelocation)
}

override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
    selectedFileLocation = fileLocationLabelString

    if(segue.identifier == "detailView") {    
        let vc = segue.destinationViewController as! DisplayWorkViewController
        vc.selectedFileLocation = selectedFileLocation
        vc.selectedLabel = selectedLabel
        vc.listLocation = TableData1
        print(vc.listLocation.count)
        print("selectedFileLocation = \(vc.selectedFileLocation)")
    }
}