0

In short, how can i manage to load a SPECIFIC uiview from a set of UIViews all contained in one XIB file? iboutlets? how?

In some cases i would like the first view displayed instead of the 2nd, sometimes i want the 3rd displayed instead of the 1st. they are all similar UIViews however only one can be displayed MODALLY presented.. I know which UIView to display depending on the user interaction with buttons being clicked.. however the question is how can i specifically select a certain view to be displayed and then attach it modally to present it.

In detail this is what i have done so far:

Hi, I have three view objects inside my TestViewController.xib file like so:

3 views present in one xib file

This xib's 'File's Owner' is connected to a TestViewController class.

On run time i am programatically instantiating the TeamViewController class like so:

TestViewController *tVController = [[TestViewController alloc] initWithNibName:@"TestViewController" bundle:nil];

I then present the view modally like so:

    UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:ls];
    [nav setModalTransitionStyle:UIModalTransitionStyleFlipHorizontal];
    [nav setModalPresentationStyle:UIModalPresentationFormSheet];
    nav.navigationBar.tintColor = [UIColor blackColor];
    [nav setNavigationBarHidden:YES]; 

    [rootViewController.navigationController presentModalViewController:nav animated:YES];
    nav.view.backgroundColor = [UIColor blackColor];
    self.modalNavController = nav;
    [nav release];
    [tVController release];

This all works and my view is loaded, however it only loads one of the views by default - automatically. What i would like to do is to be able to know how to load only a SPECIFIC UIView when instantiating the TestViewController. One way i thought of achieving this was to create IBOutlets for them and managing which view is displayed like that? so I have created three IBOutlets within the class and then connected them from the Xib's fileown to each UIView. This connected all fine.

IBOutlet *view1;
IBOutlet *view2;
IBOutlet *view3;

I am able to do something like this:

[self.view addSubview:view2]; 

and this will display view2 properly, however not in the modal view as i would ideally like it when instantiating TestViewController.

Can anyone guide me in how to achieve this goal of mine?

Thanks

Pavan
  • 17,840
  • 8
  • 59
  • 100

1 Answers1

1

You should give each of the views a unique tag, then use viewWithTag:

-EDIT-

In order for this to work, you might need to do NSNib *n = [[NSNib alloc] initWithNibNamed:bundle:]

Dustin
  • 6,783
  • 4
  • 36
  • 53
  • could you further explain how i could utilize everything from nib initialization to actually viewing the correct view and then actually making sure the right view appears in the modal view transition using your suggested methods please? – Pavan Jun 28 '12 at 12:50