Home > Software design >  SWIFT - Trouble to reload tableView data
SWIFT - Trouble to reload tableView data

Time:02-05

I will tell what is happening with my tableView, and what should happen

In Screen 1 I fetch data form API and send to a tableView on Screen 2.

On Screen 2 tableView I display an array of objects each one in one cell.

When I click on cell "X" I display a 3rd screen with some specific data for "X".

Ok, till now, everything works fine!

Then when I come back to tableView on 2nd screen and click on cell "Y" the 3rd Screen display "X" data

If I start with cell "y", the 3rd screen get stuck with "X" data and do not show "Y" data

I want that my 3rd screen get reset when I come back to 2nd screen

sorry about my english, I am working to improve and Thanks in advance.

Here is my code:

This is my 2nd screen didSelectRow function

This is my 3rd screen where i get new object from 2nd screen

This is for a job application, my first one Ty s2 s2

CodePudding user response:

Change line number 75 with

navigationController?.pushViewController(descricaoVC, animated: true)

with

let newDescricaoVC = DescricaoVC() // initialise your view controller from storyboard/ xib or whatever logic you implemented.
newDescricaoVC.oficina = oficinasArray[indexPath.row]
navigationController?.pushViewController(newDescricaoVC, animated: true)

[UPDATE]

You are pushing same VC always thats y it do not get refreshed. Either you can create new VC and push like I showed you in this answer, or if you want to save VC in memory then add viewDidAppear function in your 3rd screen and move your code from viewDidLoad to viewDidAppear

  •  Tags:  
  • Related