简体   繁体   English

快速地,在didSelectRowAt之前调用prepare

[英]In swift, prepare is invoked before didSelectRowAt

I'm trying to build a tableview in swift, when a cell is tapped, another view which contains the details of that cell will appear. 我正在尝试快速构建一个tableview,当点击一个单元格时,将出现另一个包含该单元格详细信息的视图。 I used prepare method to send an object to the second view to show the details. 我使用prepare方法将对象发送到第二个视图以显示详细信息。 However, when I tapped a cell, the second view will show information about the previously tapped cell. 但是,当我点击一个单元格时,第二个视图将显示有关先前点击的单元格的信息。 I used the didSelectRowAt to catch the current tapped cell, and used the prepare method to send the object. 我使用didSelectRowAt捕获了当前点击的单元格,并使用了prepare方法发送对象。 Is there any chance I can use one of these two methods perform this task correctly? 我是否有可能使用这两种方法之一正确执行此任务?

Any hints would be most appreciated. 任何提示将不胜感激。

Keep the segue defined, but do not connect it to selecting a row. 保持定义顺序,但不要将其连接到选择行。 Instead, you can (for example): 相反,您可以(例如):

func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
    self.performSegueWithIdentifier("mySegueIdentifier", sender: tableView)
}

override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject!) {
    if segue.identifier == "mySegueIdentifier" {
        // do your normal stuff here....
    }
}

step1: connect the whole table to the view 步骤1:将整个表连接到视图 在此处输入图片说明

step2: call below function in didSelectedRow 第二步:在didSelectedRow中调用以下函数

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM