简体   繁体   English

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

[英]Swift, how to pass tableview data to view controller?

I want to be able to pass the data filelocation to my other view controller.我希望能够将数据文件位置传递给我的其他视图控制器。 I was able to pass it but it only displays one filelocation when displayed on the view controller.我能够通过它,但在视图控制器上显示时它只显示一个文件位置。 Where I am getting multiple from the son and all the cells refer back to that one last one.我从儿子那里得到多个,所有的细胞都指向最后一个。 How can i fix this?我怎样才能解决这个问题? Heres my code:这是我的代码:

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)")
    }
}

TableData1 is the array variable and fileLocationLabelString is just a String. TableData1 是数组变量,fileLocationLabelString 只是一个字符串。 In order to get the complete list of locations, you have to pass TableData1 and not fileLocationLabelString为了获得完整的位置列表,您必须传递 TableData1 而不是 fileLocationLabelString

EDIT:编辑:

DisplayWorkViewController显示工作视图控制器

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

current view Controller当前视图控制器

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)")
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 数据将tableview单元格传递到Swift中的标签栏视图控制器 - Data pass tableview cell to tab bar view controller in Swift 在Swift中的选项卡栏中将数据从TableView传递到View Controller - Pass data from tableview to view controller in tab bar in Swift 将数据从tableview传递到Swift中的选项卡栏视图控制器。 - Pass data from tableview to tab bar view controller in Swift. Swift 4-填充表格视图并将数组/字典数据传递到详细信息视图控制器 - Swift 4 - Populate tableview and pass array/dictionary data to detail view controller 如何使用SWrevaelviewController swift 3将数据从表视图的特定行传递到另一个视图控制器 - how to pass data from a particular row of a tableview to another view controller using SWrevaelviewController swift 3 如何使用Swift将通知数据传递给View Controller - How to pass notification data to a View Controller with Swift 如何在另一个视图控制器Swift 4中将数据插入到TableView中? - How to insert data to TableView in another view controller Swift 4? 如何将解析数据从TableView传递到详细信息视图控制器? - How to pass parse data from tableview to detail view controller? 快速将TableView单元中的数据传递给视图控制器 - Swift Passing Data in a tableview cell to a view controller 无法将数据从 tableview 传递到视图控制器 - unable to pass data from tableview to view controller
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM