On refreshing UITableViews visible cells getting Realms.Exceptions.RealmInvalidObjectException Attempted to access detached row.
In my Xamarin.iOS app post login, we will check whether the same user (the previous user who had logged in last time) had logged in again or not? If the same user logs in again whatever data/models that exist in the Realm database is retained. In case a new user/different user logs in we are deleting all the data in the database and the navigation stack is reset. And post login we will sync data again. First API_1 is called to fetch a certain data (say realm_model_1) which is stored in the database and used to populate the table view. After completing API_1, another API (say API_2) is called to fetch additional data that belongs to another realm model (say realm_model_2), post which we will create a parent-child relationship between these two models by adding appropriate realm_model_1 data into a list in realm_model_2. After that, we will try to update all the visible cells in the table view. And when I call AssignmentsView.ReloadItems(AssignmentsView.IndexPathsForVisibleItems); am getting the RealmInvalidObjectException Attempted to access detached row.
Can someone point out the reason behind this exception in this scenario? All the API calls happen in a different Task and UI refresh actions happen after switching to main thread
Also observed that after logout and before login with a new user if i kill the app, launch the app again and login with the new user it wont crash.