你好 StackOverflow, 我只是 swift 拿起并尝试实现在 UITableView Cell 之间传递的数据到 UIViewController,它将显示 tableview 上显示的信息的详细 View ,每当我第一次在我的模拟器上测试应用程序时,我按下一个表格单元格它传递一个空字符串,然后当我尝试按下另一个单元格时,viewController 显示应该早先看到的字符串。我在下面粘贴了我的 tableview didSelectRowAtIndexPath 的代码。
override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
tableView.deselectRowAtIndexPath(indexPath, animated: false)
var7 = lat[indexPath.item]
var6 = long[indexPath.item]
var5 = items[indexPath.item]
var1 = detail[indexPath.item]
var2 = date[indexPath.item]
var3 = wop[indexPath.item]
var4 = ViewController()
nextView.locationPassed = var1
//self.performSegueWithIdentifier("DetailPush", sender: self)
println("value stored in var1: \(var1)")
//println("The selected indexPath is \(indexPath.item + 1)")
println("The stored id is: \(storeSend)")
}
这是我的推送转场方法的实现
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
if segue.identifier == "DetailPush"
{
if let crimesView = segue.destinationViewController as? ViewController {
crimesView.locationPassed = var1
//println("The passing address is: \(var1)")
}
}
}
知道为什么我在 segue 期间延迟获取数据吗?
谢谢
找到解决方案:我使用以下内容编辑了我的 prepareForSegue 方法,它解决了我的问题
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
//Adding the indexPath variable for the selected table Row within the segue
var indexPath: NSIndexPath = self.tableView.indexPathForSelectedRow()!
if segue.identifier == "DetailPush"
{
if let crimesView = segue.destinationViewController as? ViewController {
//Then just pass the data corresponding to the array I created identified by the index of the selected row
crimesView.locationPassed = self.arrayName[indexPath.row]
println("The passing address is: \(self.addressSend)")
}
}
}
最佳答案
我通过观看一些在线视频找到了解决方案,我为解决问题所做的一切就是重新定义我的 prepareForSegue 函数:
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
//Adding the indexPath variable for the selected table Row within the segue
var indexPath: NSIndexPath = self.tableView.indexPathForSelectedRow()!
if segue.identifier == "DetailPush"
{
if let crimesView = segue.destinationViewController as? ViewController {
//Then just pass the data corresponding to the array I created identified by the index of the selected row
crimesView.locationPassed = self.arrayName[indexPath.row]
println("The passing address is: \(self.addressSend)")
}
}
它似乎对我来说就像一个常规的 segue 一样工作......谢谢你给我的所有建议
关于ios - Segue 第一次推送 Nothing(发送数据延迟),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31566355/