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/

相关文章:

ios - 检查 objective-c 中字符数组的长度

ios - UINavigationController 添加右键

ios - 快速创建围绕图像的圆形进度条

ios - 一段时间后用户默认值更改为以前的值 - Swift

iphone - iPad 上图像的最佳尺寸是多少?

arrays - 将 switch 语句与数组一起使用时,类型 '[String]' 的表达式模式无法匹配类型 '[String]' 的值

iphone - 为什么即使在设置委托(delegate)协议(protocol)后也不会调用 UIPickerView 委托(delegate)方法?

objective-c - 在 iPhone 的 Objective-C 中查找联系人图像的路径

javascript - 启动画面后 iPhone ChildBrowser 重定向

ios - 更改场景时,应用内购买会导致应用崩溃