Swift didSelectRowAtIndexPath和prepareForSegue

时间:2015-10-24 15:43:57

标签: ios swift

我需要在所选行中添加一个值,而不是在prepareForSegue中为它执行动作。但是我的prepareForSegue正在执行它之前的操作。当我尝试放置" performSegueWithIdentifier"它崩溃了,我也把id添加到了storyboard中的segue idenfifier。我正在使用sqlite。

func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
   selectedRow = indexPath.row
}


override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
    if(segue.identifier == "editSegue")
    {
        let viewController : WorkoutView = segue.destinationViewController as! WorkoutView
        viewController.workoutInfoData = marrStudentData.objectAtIndex(selectedRow) as! WorkoutInfo
        navigationItem.title = ""
    }
}

1 个答案:

答案 0 :(得分:1)

您可以在prepare for segue

中从tableView中获取所选的indexPath
    func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
        if(segue.identifier == "editSegue")
        {
            if let indexPath = tableView.indexPathForSelectedRow{
                let viewController : WorkoutView = segue.destinationViewController as! WorkoutView
                viewController.workoutInfoData = marrStudentData.objectAtIndex(indexPath.row) as! WorkoutInfo
                navigationItem.title = ""
            }
        }
    }