Relative Content

Tag Archive for uitableviewuikittableviewiso

tableView is duplicating entries after a button is tapped to favorite a photo?

I am building an App that fetches photos via nasa api and displays them in a collectionView. I am also trying to allow the user to favorite any photo they want by clicking a favorite button. Every time I click the favorites button to favorite a photo, all the ones that I have favorited prior keeps getting reinserted into the tableView over and over and that’s the problem. The tableView keeps inserting the same photo and its metadata more than . This is really bizarre because I made sure the data model for the favorites viewcontroller isn’t duplicated. I checked the array that holds the data model and there aren’t any duplicates. In the FavoritesViewController(), I made sure that the photo object being passed isn’t inserted into the data model array if it’s already in there by comparing the their URLS, and this seems to be working. I read many similar questions on here but I couldn’t find any similar to mine.