A
A
Alexey Golovin2020-07-11 17:10:35
iOS
Alexey Golovin, 2020-07-11 17:10:35

How to update view with passed data?

There is a tabBar with two tabs. On the first tab view with a list of users. When you click on the user, a second tab opens with a view on which the user's card. I pass user'a to that controller and do profileView.viewDidLoad(). Then I track the behavior and this is what happens:

Readу to send ----- User ID: 7
viewDidLoad ----- User ID: 7
viewDidLoad ----- User ID: 7
viewDidLoad ----- User ID: 1
viewWillAppear ----- User ID: 1


Why is viewDidLoad called three times, and why is the user ID changing back to the default? If this method is not suitable, then which one should be used to update the view?

On the first tab of the tabBar there is a view with a list of users. On the second tab, a view with a user profile + a collection view with photos on it. When you click on the username, the UITapGestureRecognizer fires and opens the second tab with the profile. And now the profile should already have data with the clicked user. And accordingly the collection should be updated.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
I
Ivan Vorobei, 2020-07-11
@ivanvorobei

You don't need to use viewDidLoad to update at all. This is a life cycle method.
Describe what view you want to update - a table, just a view, a bar? For which event - what is the trigger? Write it in the question, after I will add the answer.
UPD:
Do you click on the first tabbar to open the second one?) This is not done. Looks like you're a total beginner... Check out UI design guidelines . There are literally 10 pages with pictures, there is a separate section about TabBar. I have a video about tab bar icons.
To update a collection , you need to use reloadData , performBatch , or apply depending on how you set the dataSource. You are a beginner, most likely everything will work through reloadData.
To update just view - use triggers. Delegates, notifications. Set text/image by event.

A
Alexey Golovin, 2020-07-11
@dadduUrsa

Ivan, you're right, I'm just learning. And here in the task it is said that when you click on a user in one tab, a second tab opens in which the user profile. But it's all in one tabbar. Therefore, I do not see another solution how to update the view

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question