Unexpected view cell result


I’m trying to finish the last main thing for my app.
My game tracks players playing time in a game.

I have a list of games in a tableview and you click a game it goes to a game controller that starts tracking the game and players playing time. The only problem is that you can be mid way through a game, go back to the game list and click another game and it will then change the values for a player if that game belongs to the same team that is currently playing. This obviously isn’t great for the user.

My solution is to when the game viewtable loads, find out if any of the games are in progress. If they are then disable the rows for all the games and then enable the row that is in progress. So only that one can be active. This row also highlights to the user that the game is in progress.

My code, is to reload the games whenever the game table view controller loads.

// gameViewController -> shows all the games you can track
override func viewWillAppear(_ animated: Bool) {

// 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's 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 this works when I have a game in progress. I go back to the game list and the active game is accessible and shows the little label and all the other games cells are inactive. But if I go back and reset the game, so it’s no longer active and all the games should be displayed and be active the game that was active is still active and showing active and the other games are inactive.

I’ve confirmed that when I’ve reset the game that it isn’t being classed as still active by printing out a message in the isAnyGamesInProgress() call in configureFixtureCell(). So unsure why the rows don’t seem to update, especially as I’m reloading the table when the game list controller willAppear()?? :slight_smile:

Hi @create0, I am not sure if there was a solution, I think @jonny had a question instead.