mercredi 29 juin 2016

Detail View UITableView - Pass data before segue


So in my storyboard file I have a segue from one UITableViewController going to another so that when the user taps the cell it opens the next table. Nothing special. But when they tap the cell I need to specify the data being loaded into the next view. I do this in the didSelectRowAtIndexPath. Depending on the indexPath.row I set the value of a variable that is assigned to the detail Table view in the prepareForSegue function. I have the view controller loaded as a variable in let detailViewController = segue.destinationViewController as DetailTableViewController. From here is set the data with an assignment function. However, when I tap the table the data does not show up until I press back and tap it again. Basically the data is being assigned after the segue... How can I assign the data and perform the segue afterwards?

EDIT

    override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
        switch indexPath.row {
        case 0:
            self.passedInfo = self.infoOne;
            break
        case 1:
            self.passedInfo = self.infoTwo;
            break
        case 2:
            self.passedInfo = self.infoThree;
            break
        default:
            break;
        }
    }

    override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject!) {
        let detailViewController = segue.destinationViewController as DetailTableViewController
        let destinationTitle = "Detail View"
        detailViewController.title = destinationTitle
        self.passedScores.sort{$0 > $1};
        detailViewController.setData(self.passedInfo);
    }

Aucun commentaire:

Enregistrer un commentaire