views:

31

answers:

1

I have 1 main UIViewController that contains a UITabBarController. The tab bar controller has 4 UIViewControllers (each managed by UINavigationControllers). Succinctly, it looks like this:

MainViewController
   |
   |--- FirstUIViewController
   |
   |--- SecondUIViewController
   |
   |--- ThirdUIViewController
   |
   |--- FourthUIViewController

The FirstUIViewController is loaded by default.

In the SecondUIViewController, there is an event that can occur. This event has specific data that is passed along with it. When this event occurs I want 2 things to happen:

1) FourthUIViewController to be selected in the tab bar controller to visually show a different tab has been entered.

2) A subsequent action in FourthUIViewController where a specific UITableViewCell is selected. The selected cell is determined by the data that is passed along in the event.

In order to do this, I've created an NSNotification observer in the MainViewController. It listens for the event from the SecondUIViewController and gets data from it via userInfo.

I also know that from MainViewController I can easily set the selectedIndex on the UITabBarController in order to have the correct tab shown. (#1 accomplished).

However, accomplishing #2 baffles me. I don't know how to (properly, correctly) set the selectedIndex of the tab bar and then have the FourthUiViewController act upon a selected cell. My assumption is that FourthUIViewController may not have been loaded before this event occurs so I couldn't set any parameters or call any observers.

Perhaps the broader question is how data can be passed when loading a UIViewController through tab selection (compared to pushing a new UIViewController which is very straightforward).

TIA.

A: 

If needed, there can be many recipients to a notification. Why not have your other view simply listen to the same notification and select the desired table based on the UserInfo.

Did I understand that right?

Steven Noyes
I believe the other view controller may not be initialized at the time the event is thrown (and thus wouldn't be able to listen to the event). This is assuming that view controllers are initialized until their tab is first selected.
freshfunk
In that case, it might be possible to use the NSUserDefaults to pass this information. You write the UserData to the NSUserDefaults and the new view inits from that space when it is first loaded. Once loaded, it can listen for the data from the notification.
Steven Noyes