ios - Segue 第一次推送 Nothing(发送数据延迟)

标签 ios iphone swift

你好 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/

相关文章:

iphone - 使用 UIGestureRecognizer 和点击操作进行幻灯片放映

iphone - 为什么在定义方法后会出现 "unrecognised selector sent to instance"错误?

ios - 在 iOS 中使用 Swift 保存 PDF 文件并显示它们

ios - Xcode 应用程序在 Application Loader 中上传成功但在 Build 中未看到

ios - 使用变量时NSString中的“Expression myExpression未使用”

ios - 无法快速检查提交按钮的条件

ios - 一次关闭两个 UIViewController 而不使用动画

ios - AVPlayer如何获取当前播放时间和总播放时间?

iOS 文本字段不显示占位符文本

ios - XlsxReaderWriter 创建只读 .xlsx 文件?