views:

58

answers:

1

Hello,

I have an app which plays music files. The UI has two tab views. TabOne plays the song while TabTwo displays information about the song. I have a button which sets a global variable that identifies the song to be played. The song does play but the information displayed in TabTwo does not update.

How do I ensure that both tabs update in sync when the button is tapped?

Thanks, Ritesh

A: 

You can't force another view to update by an action that occurs in another view. Instead, you have to setup the view controller to check for some data just before it's view appears.

Whenever a view is not visible on screen, you can think of it as being asleep. In the case of a tabbar, the tabbar controller only activates the view controller for the view of the tab being currently displayed. Therefore, even if you send information to a view controller when it is not active, it will not update its own interface automatically.

Instead, you have to manual setup the view controller to check for new data. Most often this is down in viewWillAppear which is called whenever the controller's view is about to be displayed (such as when its tab is selected.)

In your specific case, you need a global variable that identifies both the song and the songs data. When you press the button, the action method should set that global variable to the appropriate song. The song info tabview does nothing until the user selects its tab. At that point, the view controllers looks at the global variable and loads the information into the user interface elements before the view actually appears. From the user's perspective, the song and song info tabs appear synchronized.

I can't provide more detail without seeing your actual code or your broader app design.

TechZen