1
我有两个tableView在我的项目中运行。我试图传递(复制)我的第一个tableViewcell数据到第二个tableView.I使用tableView行动作方法传递data.My部分代码在下面.. 。在Swift中在TableView之间传递数据
第一个VC:
var tableView: UITableView!
var DataArray = ["Bus","Helicopter","Truck","Boat","Bicycle","Motorcycle","Plane","Train","Car","S cooter","Caravan"]
var sendSelectedData = NSString()
func tableView(_ tableView: UITableView, editActionsForRowAt indexPath: IndexPath) -> [UITableViewRowAction]? {
let copyAction = UITableViewRowAction(style: UITableViewRowActionStyle.normal, title: "Pass Data") { (UITableViewRowAction, NSIndexPath) -> Void in
print("Button Pressed") // Xcode Console prints **Button Pressed** when swipe action performed.
self.performSegue(withIdentifier: "send", sender: self)
}
return [copyAction]
}
func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
self.performSegue(withIdentifier: "send", sender: self)
// segue.destination as! tableController
let indexPath = tableView.indexPathForSelectedRow
let currentCell = tableView.cellForRow(at: indexPath!)!
self.sendSelectedData = (currentCell.textLabel?.text)! as String as NSString
let viewController = segue.destination as! tableController
viewController.labelcell = ([self.sendSelectedData as String])
print(self.sendSelectedData) // no result
}
二VC:
var labelcell = [String]()
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
var cell = tableView.dequeueReusableCell(withIdentifier: textCellIdentifier, for: indexPath as IndexPath) as UITableViewCell
cell.textLabel?.text = labelcell[indexPath.row] as? String
tableView.reloadData()
return cell
}
上面的代码看起来像传递数据到我的第二个VC(segue)。但是,我只是得到一个空的tableview ..
你为什么要调用'self.performSegue(withIdentifier:“send”,sender:nil)'里面准备继续? –
[将数据从TableView发送到DetailView Swift]的可能的副本(http://stackoverflow.com/questions/28430663/send-data-from-tableview-to-detailview-swift) –
@Nirav D.谢谢。我将发件人更改为自我。仍然没有结果.. – Joe