【发布时间】:2017-02-10 01:08:41
【问题描述】:
我的项目中有两个 tableView 正在运行。我正在尝试将我的第一个 tableViewcell 数据传递(复制)到第二个 tableView。我使用 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)准备转场? -
@Nirav D 。谢谢。我将发件人更改为自己。还是没有结果..
-
@DavidSeek 我已经查看了您的链接,并且在论坛中也看到了类似的问题。所有这些问题只解释了如何将数据传递给 detailview 控制器而不是 TV。你发现我的代码有什么问题吗....谢谢
-
@DavidSeek THIS PRINT WILL GET CALLED 致命错误:在 tableView.indexPathForSelectedRow 展开可选值 (lldb) 时意外发现 nil。
标签: swift uitableview