How to make an action in one view controller do the same thing on a different view controller if the content in the first view controller row is found in one of the rows in the second view controller?

Hello,


I have a topPlayers view controller with a table, a topRookies view controller with a table, and a view controller with a table for topQuarterbacks, topRunningBacks, etc. When I swipe on a row in topQuarterbacks, it performs an action to strike a line through the text, fill the row background with color, and add an accessory. If this action is performed, I want it to search through topRookies view controller and topPlayers view controller and if a match is found, I want it to do the same action in that table. I also want to be able to swipe in topPlayers view controller and topRookies view controller and search through the rest of my tables in the view controllers for a match and if one is found to perform the same action.

Accepted Reply

I figured it out.


I changed my PlayerData class to this:


class PlayerData: Codable {
    var num: Int = 0
    var numPosPick: Int = 0
    var numRookie: Int = 0
    var name: String = ""
    var team: String = ""
    var position: String = ""
    var rosterPosition: Int = -1
    var draftPosition: Int = -1
    var isTopPlayer: Bool
    var isRookie: Bool
    
    var isRostered: Bool { return rosterPosition >= 0 }
    var isDrafted: Bool { return draftPosition >= 0 }
    
    init(num: Int, numPosPick: Int, numRookie: Int, name: String, team: String, position: String, isTopPlayer: Bool, isRookie: Bool) {
        self.num = num
        self.numPosPick = numPosPick
        self.numRookie = numRookie
        self.name = name
        self.team = team
        self.position = position
        self.isTopPlayer = isTopPlayer
        self.isRookie = isRookie
    }
}

Adding isTopPlayer and isRookie to confirm if the player is in the top 200 or if the player is a rookie or if the player is both.


I had to do a few tweaks but it works just the way I want it to now.

Replies

Hard to read, let edit a little.


I have a topPlayers view controller with

- a table,

- a topRookies view controller with a table, and

- a view controller with a table for topQuarterbacks, topRunningBacks, etc.


When I swipe on a row in topQuarterbacks, it performs an action to strike a line through the text, fill the row background with color, and add an accessory.

If this action is performed, I want it to search through topRookies view controller and topPlayers view controller and if a match is found, I want it to do the same action in that table.

I also want to be able to swipe in topPlayers view controller and topRookies view controller and search through the rest of my tables in the view controllers for a match and if one is found to perform the same action.


You are trying to sync data between different views manually and that's a bad way of doing, creating tight coupling between view controllers.


What you need to do:

- make change in topQuarterbacks as you do now

- reflect those changes in a global data model, which is independant of the viewController: a class holding the data structures with func to save or read data in and out.

Note: this can also be done through a permanent database storage as you've seen.

- when data are changed, post a notification

- all controllers that may need to be updated (topPlayers, topRookies) will subscribe to this notification.

- on reception of notification, they will update their dataSource (if concerned by the change) by reading from the global data model and call table.reload


Note: the topQuarterbacks could also subscribe. In such a case, it will receive its own notification. you should either:

- just let update occur twice

- in the function triggered by notication, test if it was sent by itself and then ignore

- or better, update topQuarterbacks dataSource by reading the global dataModel, like any other VC.

Doing so, you will be able to update data from other VC if you want (topPlayers, topRookies) and get update in topQuarterbacks

Yes, I agree to update the data source. How do I update the data source in topQuarterbacks for a quarterback when the data source is changed in topPlayers?


For example:

I perform the addPlayer action for Patrick Mahomes in topPlayers. At bthe same time, I want to update allPlayers for Patrick Mahomes.


init() {
        allPlayers = [PlayerData]()
        topRookies = [PlayerData]()
        topPlayers = [PlayerData]()
        
        if let playerList = playersReadFromDisk() {
            allPlayers = playerList
        } else {
            allPlayers = [
                // Quarterbacks
                PlayerData(num: 1, name: "Patrick Mahomes", team: "KC", position: "QB"),
                PlayerData(num: 2, name: "Deshaun Watson", team: "HOU", position: "QB"),
                PlayerData(num: 3, name: "Aaron Rodgers", team: "GB", position: "QB"),
                PlayerData(num: 4, name: "Matt Ryan", team: "ATL", position: "QB"),
                PlayerData(num: 5, name: "Baker Mayfield", team: "CLE", position: "QB"),
                PlayerData(num: 6, name: "Carson Wentz", team: "PHI", position: "QB"),
                PlayerData(num: 7, name: "Jared Goff", team: "LAR", position: "QB"),
                PlayerData(num: 8, name: "Cam Newton", team: "CAR", position: "QB"),
                PlayerData(num: 9, name: "Andrew Luck", team: "IND", position: "QB"),
                PlayerData(num: 10, name: "Drew Brees", team: "NO", position: "QB"),
                PlayerData(num: 11, name: "Ben Roethlisberger", team: "PIT", position: "QB"),
                PlayerData(num: 12, name: "Dak Prescott", team: "DAL", position: "QB"),
                PlayerData(num: 13, name: "Russell Wilson", team: "SEA", position: "QB"),
                PlayerData(num: 14, name: "Kyler Murray", team: "ARI", position: "QB"),
                PlayerData(num: 15, name: "Tom Brady", team: "NE", position: "QB"),
                PlayerData(num: 16, name: "Lamar Jackson", team: "BAL", position: "QB"),
                PlayerData(num: 17, name: "Mitchell Trubisky", team: "CHI", position: "QB"),
                PlayerData(num: 18, name: "Jameis Winston", team: "TB", position: "QB"),
                PlayerData(num: 19, name: "Philip Rivers", team: "LAC", position: "QB"),
                PlayerData(num: 20, name: "Kirk Cousins", team: "MIN", position: "QB"),
                PlayerData(num: 21, name: "Derek Carr", team: "OAK", position: "QB"),
                PlayerData(num: 22, name: "Sam Darnold", team: "NYJ", position: "QB"),
                PlayerData(num: 23, name: "Josh Allen", team: "BUF", position: "QB"),
                PlayerData(num: 24, name: "Matthew Stafford", team: "DET", position: "QB"),
                PlayerData(num: 25, name: "Marcus Mariota", team: "TEN", position: "QB"),
                PlayerData(num: 26, name: "Jimmy Garoppolo", team: "SF", position: "QB"),
                PlayerData(num: 27, name: "Andy Dalton", team: "CIN", position: "QB"),
                PlayerData(num: 28, name: "Eli Manning", team: "NYG", position: "QB"),
                PlayerData(num: 29, name: "Nick Foles", team: "JAC", position: "QB"),
                PlayerData(num: 30, name: "Joe Flacco", team: "DEN", position: "QB")
          ]
     }
if let topRookiesList = topRookiesReadFromDisk() {
            topRookies = topRookiesList
        } else {
            topRookies = [
                PlayerData(num: 1, name: "Josh Jacobs", team: "OAK", position: "RB"),
                PlayerData(num: 2, name: "David Montgomery", team: "CHI", position: "RB"),
                PlayerData(num: 3, name: "Miles Sanders", team: "PHI", position: "RB"),
                PlayerData(num: 4, name: "A.J. Brown", team: "TEN", position: "WR"),
                PlayerData(num: 5, name: "N'Keal Harry", team: "NE", position: "WR"),
                PlayerData(num: 6, name: "JJ Arcega-Whiteside", team: "PHI", position: "WR"),
                PlayerData(num: 7, name: "DK Metcalf", team: "SEA", position: "WR"),
                PlayerData(num: 8, name: "Kyler Murray", team: "ARI", position: "QB"),
                PlayerData(num: 9, name: "T.J. Hockenson", team: "DET", position: "TE"),
                PlayerData(num: 10, name: "Andy Isabella", team: "ARI", position: "WR"),
                PlayerData(num: 11, name: "Marquise Brown", team: "BAL", position: "WR"),
                PlayerData(num: 12, name: "Deebo Samuel", team: "SF", position: "WR"),
                PlayerData(num: 13, name: "Mecole Hardman", team: "KC", position: "WR"),
                PlayerData(num: 14, name: "Noah Fant", team: "DEN", position: "TE"),
                PlayerData(num: 15, name: "Parris Campbell", team: "IND", position: "WR"),
                PlayerData(num: 16, name: "Devin Singletary", team: "BUF", position: "RB"),
                PlayerData(num: 17, name: "Darrell Henderson", team: "LAR", position: "RB"),
                PlayerData(num: 18, name: "Damien Harris", team: "NE", position: "RB"),
                PlayerData(num: 19, name: "Hakeem Butler", team: "ARI", position: "WR"),
                PlayerData(num: 20, name: "Diontae Johnson", team: "PIT", position: "WR")
          ]
     }
if let top200PlayersList = topPlayersReadFromDisk() {
            topPlayers = top200PlayersList
        } else {
            topPlayers = [
                PlayerData(num: 1, name: "Saquon Barkley", team: "NYG", position: "RB"),
                PlayerData(num: 2, name: "Christian McCaffrey", team: "CAR", position: "RB"),
                PlayerData(num: 3, name: "Alvin Kamara", team: "NO", position: "RB"),
                PlayerData(num: 4, name: "DeAndre Hopkins", team: "HOU", position: "WR"),
                PlayerData(num: 5, name: "Michael Thomas", team: "NO", position: "WR"),
                PlayerData(num: 6, name: "Ezekiel Elliott", team: "DAL", position: "RB"),
                PlayerData(num: 7, name: "Davante Adams", team: "GB", position: "WR"),
                PlayerData(num: 8, name: "David Johnson", team: "ARI", position: "RB"),
                PlayerData(num: 9, name: "Le'Veon Bell", team: "NYJ", position: "RB"),
                PlayerData(num: 10, name: "Todd Gurley II", team: "LAR", position: "RB"),
                PlayerData(num: 11, name: "Julio Jones", team: "ATL", position: "WR"),
                PlayerData(num: 12, name: "Tyreek Hill", team: "KC", position: "WR"),
                PlayerData(num: 13, name: "Odell Beckham Jr.", team: "CLE", position: "WR"),
                PlayerData(num: 14, name: "Kerryon Johnson", team: "DET", position: "RB"),
                PlayerData(num: 15, name: "Joe Mixon", team: "CIN", position: "RB"),
                PlayerData(num: 16, name: "James Conner", team: "PIT", position: "RB"),
                PlayerData(num: 17, name: "JuJu Smith-Schuster", team: "PIT", position: "WR"),
                PlayerData(num: 18, name: "Antonio Brown", team: "OAK", position: "WR"),
                PlayerData(num: 19, name: "Mike Evans", team: "TB", position: "WR"),
                PlayerData(num: 20, name: "Dalvin Cook", team: "MIN", position: "RB"),
                PlayerData(num: 21, name: "Travis Kelce", team: "KC", position: "TE"),
                PlayerData(num: 22, name: "Nick Chubb", team: "CLE", position: "RB"),
                PlayerData(num: 23, name: "Patrick Mahomes", team: "KC", position: "QB"),
                PlayerData(num: 24, name: "Leonard Fournette", team: "JAC", position: "RB"),
                PlayerData(num: 25, name: "Keenan Allen", team: "LAC", position: "WR"),
                PlayerData(num: 26, name: "Amari Cooper", team: "DAL", position: "WR"),
                PlayerData(num: 27, name: "George Kittle", team: "SF", position: "TE"),
                PlayerData(num: 28, name: "Zach Ertz", team: "PHI", position: "TE"),
                PlayerData(num: 29, name: "Josh Jacobs", team: "OAK", position: "RB"),
                PlayerData(num: 30, name: "Deshaun Watson", team: "HOU", position: "QB")
          ]
     }
}

Yes, I agree to update the data source. How do I update the data source in topQuarterbacks for a quarterback when the data source is changed in topPlayers?


Did you try what I proposed ?

What you need to do:

- make change in topQuarterbacks as you do now

- reflect those changes in a global data model, which is independant of the viewController: a class holding the data structures with func to save or read data in and out.

Note: this can also be done through a permanent database storage as you've seen.

- when data are changed, post a notification

- all controllers that may need to be updated (topPlayers, topRookies) will subscribe to this notification.

- on reception of notification, they will update their dataSource (if concerned by the change) by reading from the global data model and call table.reload



What are the datasources (the arrays) in your 3 views ?

What is the global data model ?


The code you show is in which class ?


init() {
        allPlayers = [PlayerData]()
        topRookies = [PlayerData]()
        topPlayers = [PlayerData]()
     
        if let playerList = playersReadFromDisk() {
            allPlayers = playerList
        } else {
            allPlayers = [
                // Quarterbacks
                PlayerData(num: 1, name: "Patrick Mahomes", team: "KC", position: "QB"),
               // next
               ]
     }
     if let topRookiesList = topRookiesReadFromDisk() {
            topRookies = topRookiesList
        } else {
            topRookies = [
                PlayerData(num: 1, name: "Josh Jacobs", team: "OAK", position: "RB"),
               // next
               ]
     }
     if let top200PlayersList = topPlayersReadFromDisk() {
            topPlayers = top200PlayersList
        } else {
            topPlayers = [
                PlayerData(num: 1, name: "Saquon Barkley", team: "NYG", position: "RB"),
               // next
               ]
     }
}

The code is show is in Database class.


class Database {
    
    static let shared = Database()
    
    // All players
    fileprivate var allPlayers: [PlayerData]
    
    fileprivate func playerDataURL() -> URL {
        let documentDirectoryURL = FileManager.default.urls(for: .documentDirectory, in:.userDomainMask).last!
        return documentDirectoryURL.appendingPathComponent("playerData.json")
    }
    
    fileprivate func playersWriteToDisk() {
        do {
            let data = try JSONEncoder().encode(allPlayers)
            try data.write(to: playerDataURL())
        } catch let error as NSError {
            NSLog("Error reading file: \(error.localizedDescription)")
        }
    }
    
    fileprivate func playersReadFromDisk() -> [PlayerData]? {
        let filePlayerURL = playerDataURL()
        guard FileManager.default.fileExists(atPath: filePlayerURL.path) else {
            return nil
        }
        do {
            let fileContents = try Data(contentsOf: filePlayerURL)
            let list = try JSONDecoder().decode([PlayerData].self, from: fileContents)
            return list
        } catch let error as NSError {
            NSLog("Error reading file: \(error.localizedDescription)")
        }
        return nil
    }
    
    func playerList(position: String) -> [PlayerData] {
        return allPlayers.filter({ $0.position == position })
    }
    
    // Top rookies
    fileprivate var topRookies: [PlayerData]
    
    fileprivate func topRookiesDataURL() -> URL {
        let documentDirectoryURL = FileManager.default.urls(for: .documentDirectory, in:.userDomainMask).last!
        return documentDirectoryURL.appendingPathComponent("topRookiesData.json")
    }
    
    fileprivate func topRookiesWriteToDisk() {
        do {
            let data = try JSONEncoder().encode(topRookies)
            try data.write(to: topRookiesDataURL())
        } catch let error as NSError {
            NSLog("Error reading file: \(error.localizedDescription)")
        }
    }
  
    fileprivate func topRookiesReadFromDisk() -> [PlayerData]? {
        let filePlayerURL = topRookiesDataURL()
        guard FileManager.default.fileExists(atPath: filePlayerURL.path) else {
            return nil
        }
        do {
            let fileContents = try Data(contentsOf: filePlayerURL)
            let list = try JSONDecoder().decode([PlayerData].self, from: fileContents)
            return list
        } catch let error as NSError {
            NSLog("Error reading file: \(error.localizedDescription)")
        }
        return nil
    }
    
    func topRookiesList() -> [PlayerData] {
        return topRookies
    }
    
    // Top 200 Players
    fileprivate var topPlayers: [PlayerData]
    
    fileprivate func topPlayersDataURL() -> URL {
        let documentDirectoryURL = FileManager.default.urls(for: .documentDirectory, in:.userDomainMask).last!
        return documentDirectoryURL.appendingPathComponent("topPlayersData.json")
    }
    
    fileprivate func topPlayersWriteToDisk() {
          do {
              let data = try JSONEncoder().encode(topPlayers)
              try data.write(to: topPlayersDataURL())
          } catch let error as NSError {
              NSLog("Error reading file: \(error.localizedDescription)")
          }
      }
    
    fileprivate func topPlayersReadFromDisk() -> [PlayerData]? {
        let filePlayerURL = topPlayersDataURL()
        guard FileManager.default.fileExists(atPath: filePlayerURL.path) else {
            return nil
        }
        do {
            let fileContents = try Data(contentsOf: filePlayerURL)
            let list = try JSONDecoder().decode([PlayerData].self, from: fileContents)
            return list
        } catch let error as NSError {
            NSLog("Error reading file: \(error.localizedDescription)")
        }
        return nil
    }
    
    func topPlayersList() -> [PlayerData] {
        return topPlayers
    }
    
    // myRoster/My Team
    func rosterList() -> [PlayerData] {
        let rosteredPlayers = allPlayers.filter { ($0.rosterPosition >= 0)}
        return rosteredPlayers.sorted(by: { $0.rosterPosition < $1.rosterPosition })
    }
    
    func rosterArray() -> [PlayerData] {
        let roster = rosterList()
        return roster
    }
    
    func draftList() -> [PlayerData] {
        let draftedPlayers = allPlayers.filter({ $0.draftPosition >= 0 })
        return draftedPlayers.sorted(by: { $0.draftPosition < $1.draftPosition })
    }
    
    func addToRosterList(player: PlayerData) {
        let maxRosteredIndex = allPlayers.map({ $0.rosterPosition }).max()!
        player.rosterPosition = maxRosteredIndex + 1
    }
    
    func addToDraftList(player: PlayerData) {
        let maxDraftedIndex = allPlayers.map({ $0.draftPosition }).max()!
        player.draftPosition = maxDraftedIndex + 1
    }
    
    fileprivate func removeFromRosterList(player: PlayerData) {
        let currentRosterPosition = player.rosterPosition
        player.rosterPosition = -1 // No longer on the rosterList. Gets all players on roster at a higher index.
        let higherNumberedRosterPlayers = allPlayers.filter({ $0.rosterPosition > currentRosterPosition}) // Their rosterPositions have now gone down by one.
        
        for otherPlayer in higherNumberedRosterPlayers {
            otherPlayer.rosterPosition -= 1 // Decrease position by 1.
        }
    }
    
    func removeFromLists(player: PlayerData) {
        removeFromRosterList(player: player)
        removeFromDraftList(player: player)
    }
    
    fileprivate func removeFromDraftList(player: PlayerData) {
        let currentDraftPosition = player.draftPosition
        player.draftPosition = -1 // No longer on the rosterList. Gets all players on roster at a higher index.
        let higherNumberedRosterPlayers = allPlayers.filter({ $0.draftPosition > currentDraftPosition}) // Their rosterPositions have now gone down by one.
                
        for otherPlayer in higherNumberedRosterPlayers {
            otherPlayer.draftPosition -= 1 // Decrease position by 1.
        }
    }
    
    func changeMade() {
        playersWriteToDisk()
    }
    
    init() {
        allPlayers = [PlayerData]()
        topRookies = [PlayerData]()
        topPlayers = [PlayerData]()
        
        if let playerList = playersReadFromDisk() {
            allPlayers = playerList
        } else {
            allPlayers = [
                // Quarterbacks
                PlayerData(num: 1, name: "Patrick Mahomes", team: "KC", position: "QB"),
                PlayerData(num: 2, name: "Deshaun Watson", team: "HOU", position: "QB"),
           
...all of the previous code from my last comment.  

Each view has an array called objectsArray.

class Top30Quarterbacks_20192020: UIViewController, UITableViewDelegate, UITableViewDataSource {
    
    var objectsArray = [PlayerData]()
    
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return objectsArray.count
    }
    
    override func viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(animated)
        objectsArray = Database.shared.playerList(position: "QB")
    }


Is this considered a global data model? What do you mean by that?

Yes, this is a global model.


Could you check everywhere that viewWillAppear is called when you return ?

If the transition is automatic, this may not be the case.

    override func viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(animated)
        objectsArray = Database.shared.playerList(position: "QB")
        print("ViewWillAppear Top30Quarterbacks_20192020)
    }

What do you mean by 'transition automatic'?


This is what all of my viewWillAppear looks like.


class Top80RunningBacks_20192020: UIViewController, UITableViewDelegate, UITableViewDataSource {
    
    var objectsArray = [PlayerData]()
    
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return objectsArray.count
    }
    
    override func viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(animated)
        objectsArray = Database.shared.playerList(position: "RB")
    }


class Top80WideReceivers_20192020: UIViewController,UITableViewDelegate, UITableViewDataSource {
    
    var objectsArray = [PlayerData]()
    
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return objectsArray.count
    }
    
    override func viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(animated)
        objectsArray = Database.shared.playerList(position: "WR")
    }


class Top30TightEnds_20192020: UIViewController, UITableViewDelegate, UITableViewDataSource {
    
    var objectsArray = [PlayerData]()
    
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return objectsArray.count
    }
    
    override func viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(animated)
        objectsArray = Database.shared.playerList(position: "TE")
    }


class Top15Defenses_20192020: UIViewController, UITableViewDelegate, UITableViewDataSource {
    
    var objectsArray = [PlayerData]()
    
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return objectsArray.count
    }
    
    override func viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(animated)
        objectsArray = Database.shared.playerList(position: "DEF")
    }


class Top15Kickers_20192020: UIViewController, UITableViewDelegate, UITableViewDataSource {
    
    var objectsArray = [PlayerData]()
    
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return objectsArray.count
    }
    
    override func viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(animated)
        objectsArray = Database.shared.playerList(position: "K")
    }

Transition Automatic:

- In IB, select the viewController

- open the attributes Inspector

- You have a field named Transition

- It is usually set to Automatic.

- Select fullScreen insted.


If you are in a navigationController, do it for the navController and all its children.


Did you make the check in ViewWillAppear:

        print("ViewWillAppear Top30Quarterbacks_20192020)

In the attributes inspector, there is only a Transition Style field. It is set to Cover Vertical. There is a Presentation field that is set to Automatic.


Yes I did add


print("ViewWillAppear Top30Quarterbacks_20192020")


in viewWillAppear

Sorry, it is the presentation to set to full screen.


do you get the print in log when you return to a VC ?

Yes it does show up when I return to the view.


I also added in Top80RunningBacks_20192020 class


print("ViewWillAppear Top80RunningBacks_20192020")


When I return to Top80RunningBacks_20192020 view I get this in log:


ViewWillAppear Top80RunningBacks_20192020


But when I return to Top30Quarterbacks_20192020 view I get this in log:


ViewWillAppear Top30Quarterbacks_20192020

along with a bunch of other stuff

The date, the time, the name of the app, storyboard, and unknown class.


I tried to copy and paste it but it kept saying 'Currently being moderated'

I tried to copy and paste it but it kept saying 'Currently being moderated'

Have you a url inside what you paste ?

If so edit as h ttps://


After viewWillAppear, where do you reload data ?

You could do it there.


class Top80RunningBacks_20192020: UIViewController, UITableViewDelegate, UITableViewDataSource { 
     
    var objectsArray = [PlayerData]() 
     
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { 
        return objectsArray.count 
    } 
     
    override func viewWillAppear(_ animated: Bool) { 
        super.viewWillAppear(animated) 
        objectsArray = Database.shared.playerList(position: "RB") 
        tableView.reloadData()
    }


Of course, in each class, you must have a

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {

hi,


first, let's thank Claude31 for his contributions to this thread the last several days.


i have stayed away until now, only because the app design has changed since last week -- see the thread How do I save and load an array into a table view using singleton database option? -- there are now more lists, more view controllers (some we never knew about) ... and there's a lot of view reloading and updating issues which i think are based on the app using modal segues (and in iOS 13, these got more interesting to handle, since viewDidLoad() may not be getting called when modals are dismissed, depending on how they are presented).


i'd like to suggest to japio that we simplify the app design by not inventing more lists for the Database to manage, but instead by placing markers in each player's record as to whether they are top200, a rookie, and so forth. saving multiple lists to disk is not difficult, but it is confusing and maintenance-heavy: look how much code has been duplicated in the Database to handle different lists.


also, with multiple lists, player data is being duplicated on disk in multiple locations, and one must be sure that the data never gets out of sync ... and this creates a lot of code in the app of the form "edit a player in a list, but be sure to edit the player in all the other lists in which he appears."


with that, i've posted a newer version of what i think could make a small, relevant project. it's only a suggestion, but i hope you'll see some of the simplifications i am proposing. i've tried to add many comments to explain my choices, one of which is to not keep the lists of interest in order (that feature can be added, but it was never clear to me that it was required). all segues (in fact, you'll see that there's only one segue) are pushes, so i have avoided the refresh/update issues of dismissing modal segues.


the project is located as before, at: bitbucket.org/delawaremathguy/japio



hope that helps,

DMG

Hello,


I checked out your bitbucket. Thank you for your help.


I have always had a lot of views in my app but I only mentioned a few because mentioning all of them would have been a lot more code. Most of my views have the same structure so I thought I would just copy and paste and make miner adjustments. I can't figure out how your code works with the structure of my app. Let me explain my app.


1. I have a main view controller with a table view and it has seasons in it. The first row is season 2019/2020.


2. When click on season 2019/2020 row, it segues to a new view controller that has a table view. The table view looks like the following:

Overall Top 200

Top 60 Rookies

Top 30 Quarterbacks

Top 80 Running Backs

Top 80 Wide Receivers

Top 30 Tight Ends

Top 15 Defenses

Top 15 Kickers


Under this table view, I have 2 buttons:


My Team

Draft Order


3. I can view my team or view the draft order by clicking on these buttons. When I click on one of the table view rows such as Top 30 Quarterbacks, it segues to another view controller that has a list of the top 30 quarterbacks.


4. When I swipe to add a quarterback, it adds the quarterback in the swiped row to my team(myRoster). It also adds a strike through line through the text, adds a checkmark accessory, and changes the color of the cell. When it does this, I want it to do the same thing to the same player in Overall Top 200 and Top 60 Rookies if the player is found. If the player isn't found in those views, I want it to do nothing in those other views.


5. If Overall Top 200 is selected, it segues to another view that displays the top 200 players. If a row with a player is added, I want it to do the same thing in the other views if the player is found. If the player isn't found, I want it to do nothing.



The app works exactly how I want it to except for this function.

ViewWillAppear Top30Quarterbacks_20192020

along with a bunch of other stuff

The date, the time, the name of the app, storyboard, and unknown class.


Which is this unknown class ? May be it is just not found.

5. If Overall Top 200 is selected, it segues to another view that displays the top 200 players. If a row with a player is added, I want it to do the same thing in the other views if the player is found. If the player isn't found, I want it to do nothing.


It is a bit hard to find onseself in the code.

Could you post the complete add function you speak here (and tell in which class).


Did you try to post notification when added ?

If not, you should.

If yes, could you show in another view how you handle the notification:

- subscription

- action on receiving notification


Of cours, that suppose the view is loaded.

If not, pit should update its data from pêrmanent storage (which should be up to date) in viewDidLoad when being loaded