0
votes

EDIT 2: Added a half-solution at bottom. Still open to a full solution

EDIT 1: Added images.

I need help fixing navigation between a second and third tableview.

I have a Navigation Controller, and three table views. The first two show up fine such that clicking a dynamic tableview cell > in the first tableview moves to the second tableview. However the second tableview cell chevron > while set in the storyboard (Accessory: Disclosure Indicator) doesn't show up during runtime, and therefore clicking on it does not move to the third tableview. I need help fixing that.

In each case I Ctrl+linked the cells to the next tableview in storyboard as show, and have prepare for segue in the previous tableview controllers. However only one works and the other seems orphaned.

If you could suggest a checklist in making sure the Navigation Controller works across three tableviews that would be helpful. Not sure what code to show so I'll post both segues. But it might not be a segue issue so I don't know.

first tableview Weeks works going to second tableview Leagues. Loads json file depending on what is clicked.

override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
    if segue.identifier == "toLeagues"
    {
            let leaguesController = segue.destination as! LeaguesViewController
            // pass the selected row
            let selectedRow = self.tableView.indexPath(for: sender as! UITableViewCell)!.row
            if selectedRow == 0
            {
                leaguesController.weekFileName = "sports_week_1"
            }
            else
            {
                leaguesController.weekFileName = "sports_week_2"
            }
    }

But second tableview Leagues doesn't work going to third tableview Games

override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
    if segue.identifier == "toGames"
    {

        let gamesController = segue.destination as! GamesViewController
        // pass the selected row
        let selectedRow = self.tableView.indexPath(for: sender as! UITableViewCell)!.row

        gamesController.gameName = selectedRow.description
    }
}

EDIT 1: Added images:

Starts off fine in first tableview...
starts off fine, get > to move to next view

Stops here in second tableview, can't move to third tableview enter image description here

EDIT 2: Half solution

I found a half solution. Menu item now opens new view, only that the chevron appears after the fact. didSelectRowAt adds the missing disclosure indicator directly and goes to the new view controller. Couldn't find a viewWillAppear with IndexPath so I opted for didSelectRowAt. Works when clicked at least. Just the disclosure indicator missing on initial load. How to load the accessoryType before the view runs?

func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {

        let cell = tableView.cellForRow(at: indexPath)
        cell?.accessoryType = .disclosureIndicator

        // force menu to move to GamesViewController
        let myGamesView = self.storyboard!.instantiateViewController(withIdentifier: "gamesView")
        self.navigationController?.pushViewController(myGamesView, animated: true)
    }
1
Can you add cellForRow for LeaguesViewController .Nirav D

1 Answers

0
votes

Try setting accessoryType in cellForRowAt instead of didSelectRowAt.

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
    let cell = tableView.dequeueReusableCell(withIdentifier: "yourIdentifier") as! YourCustomCell

    //Your other code
    cell.accessoryType = .disclosureIndicator
    return cell 
}