I have a small application that tracks players playing time in a sports game. I have a list of sports games, and you can click one at a time and start tracking game details. I try to make sure that if the game is on and the user returns to the list of games, they cannot click on another game cell, since it overwrites all the current data in the active game.
I almost did this job. When the game is on, and I return to the list of sports games, only the active is available, and it shows the user that he is active. But when I come back and reset this game, I expect the tableView of sports games to become available. But this is not so. It still shows only one active game, and all other games are not available. I am using tableView.reloadData in viewWillAppear. I also showed the corresponding code below.
// gameViewController -> shows all the games you can track override func viewWillAppear(_ animated: Bool) { self.tableView.reloadData() for game in fetchedResultsController.fetchedObjects! { print("Game Opposition is \(game.opposition)") print("Is Playing? \(game.isPlaying)") print("Current Playing Time \(game.currentGameTime)") print("----------------------") } } // game cell view controller -> checks to see if any games are in progress func isAnyGamesInProgress(games: [Game]) -> Bool { let inProgressGames = games.filter({ Int($0.currentGameTime) > 0 && $0.gameComplete == false }) if inProgressGames.isEmpty { return false } return true } // configures the games cells in tableview func configureFixtureCell(fixture: Game){ oppositionLabel.text = "\(fixture.team.name) v \(fixture.opposition)" // check if any games are currently in progress, if so disable all the other cells // this prevents a user being mid game and checking an old game and inadvertently updating all the played time values let games = fixture.team.game?.allObjects as! [Game] if isAnyGamesInProgress(games: games){ isUserInteractionEnabled = false inPlayLabel.isHidden = true // identifies that this game is in progress } // unset the sole game who in progress if Int(fixture.currentGameTime) > 0 && !fixture.gameComplete { isUserInteractionEnabled = true // makes this cell active // show label as green dot inPlayLabel.isHidden = false inPlayLabel.layer.cornerRadius = 8 inPlayLabel.layer.masksToBounds = true } }
Now it works when I have a game. I return to the list of games, and the active game is available and displays a small label, and all other game cells are inactive. But if I go back and reset the game so that it is no longer active, all games should be displayed and accessible. But the active game is still displayed as active, and all other game cells are not available.
I confirmed that when I have reset the game, which it does not classify as still active, by printing the message in the call to isAnyGamesInProgress () in configureFixtureCell (). So uncertainty about why the rows don't seem to be updated, especially when I reload the table when the playlist controller willAppear ()? and I donβt cache the result of NSFecthController games :)
I added some images to show console output. Bootstrap first

The game continues 
After the game reset 
ios uitableview swift
Jonnny
source share