2 Replies
      Latest reply on Nov 11, 2019 2:20 PM by RaisingElephants
      RaisingElephants Level 1 Level 1 (0 points)

        Hello:

         

        I am currently running on xCode 11.2 on Catalina. I am learning IOS programming and I decided to put together an app that lists a group of areas for the user, the user can then select an area and see the weather for that area in the NOAA website. Simple enough right?

         

        I have a single navigator pointing to a Table-view that segues to another View which I use for my details view. I have a ViewController for each of these views. Let's call them TableViewController and DetailViewController. One more part to this is that the user can search in the table-view of the areas using a searchController.

         

        Ok, the areas load perfectly into the Table-view and the searching works fine as well. To capture the user's selection and display the appropriate weather for the selected area. On the TableViewController I am using the following:

         

        override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
                if segue.identifier == "showdetail" { 
                    if let indexPath = tableView.indexPathForSelectedRow {
                        let controller = segue.destination as? DetailViewController
                        if isFiltering {
                          controller?.area = filteredTableData[indexPath.row]
                        } else {
                          controller?.area = Areas[indexPath.row]
                        }
                    }
                }
            }
        
        override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
                performSegue(withIdentifier: "showdetail", sender: self)
            }

         

        The ".area" object is the class that holds all the details for the area the user has selected. This is the ONLY reference that I make to the target DetailViewController (or any of its objects). When they make their choice they are taken to the DetailViewController which loads the forecast just fine. HOWEVER, as soon as the user clicks the 'back' navigational button to go back to the Table-view. I get the following error in the debug area:

         

        2019-11-05 15:05:24.611629-0700 myWeatherApp[3252:595075] [ProcessSuspension] 0x136af73f0 - ProcessAssertion::processAssertionWasInvalidated()

        2019-11-05 15:05:29.259239-0700 myWeatherApp[3252:595075] [ProcessSuspension] 0x136af7d20 - ProcessAssertion::processAssertionWasInvalidated()

         

        The Table-view with all the areas loads fine and the user is able to make additional selections but when they choose to go back to the table-view they always get the 2 error lines mentioned above. On the raywanderlich forums a recommendation was provided by 'stevecaine' that this error is received when 'WKWebView is released from memory' but something else is still referencing it and that to solve this issue you should 'keep a reference to the ‘DetailViewController’ in a property on the main view controller'. So then I made these changes on the TableViewController:

         

        // in the declarations area
        var detailsVC: DetailViewController? = nil

         

        And then on the prepare for segue function:

         

        override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
                if segue.identifier == "showdetail" {  
                    if let indexPath = tableView.indexPathForSelectedRow {
                        let controller = segue.destination as? DetailViewController
                        if isFiltering {
                          controller?.area = filteredTableData[indexPath.row]
                        } else {
                          controller?.area = Areas[indexPath.row]
                        }
                        detailsVC = controller  // THIS IS THE LINE I ADDED
                    }
                }
            }

         

        Now when the user makes a selection and they go back to the Table-view there is no error, yay!.....BUT when they make a new selection from the Table-view the error returns as the weather details for the newly selected area load up in the details view. This is the case with every subsequent selection: No error when the user returns to the Table-view listing but when they make another selection then the error returns. So keeping a reference to the DetailsViewController only works on the first selection but on any subsequent ones the error returns.

         

        A couple of other things that I have noticed:

        1. The first time that the user makes a selection the webview takes quite a bit of time to load the page.

        2. After I have received the original errors mentioned above (meaning after the user has at least made one prior selection), I also get the error mentioned below. But this error is not really something that I get because of an action the user is taking in the app since the user may just be sitting at the table list view and the error appears:

         

        2019-11-05 15:05:32.106727-0700 myWeatherApp[3252:595075] Could not signal service com.apple.WebKit.WebContent: 113: Could not find specified service

        2019-11-05 15:05:32.108500-0700 myWeatherApp[3252:595075] Could not signal service com.apple.WebKit.Networking: 113: Could not find specified service

         

        3. When the app first loads, if I make a selection and I am taken to the detail-view and click the 'back' button to the table-view BEFORE the webview finishes loading and make any subsequent selections the same way (not letting the webview finish loading the weather content) I get no errors at all. What gives?

         

        My questions:

        1. Is there anything glaring that I am missing?

        2. Am I supposed to be somehow cleaning out, destroying or setting to nil the detailsview or the webview when the user leaves to go back to the Table-view listing? cause I am NOT doing any of that.

        3. When I am running the code in the simulator I have noticed that the memory usage on my machine is high. Could this be a problem? It almost seems like the de-referencing of the webview, which if it happens automatically, is not happening fast enough so that when the user makes another selection or hits the back button that the error comes up.

         

        A couple of things that I should mention. First, the webview has been added to the Details-view via the SB NOT through code. So I load its content during the viewDidLoad function using the passed "area" object. Second, I know that there may be easier ways to do this on regards to my design of the project (although it seems basic enough) but the purpose of this is to learn how some of these components work so I have a better understanding of future projects.

         

        Any help at all would help a great deal.

        Thanks.