[英]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.