How do I load a NIB that is not a view in a UITabViewController?

I want to load a thread that is not a view in a UITabViewController. Here's what I have now and it doesn't work, but it should give you an idea of ​​what I want:

- (IBAction)PlaylistButtonPressed:(id)sender
{
    MusicPick *music = [[MusicPick alloc] initWithNibName:@"MusicPick" bundle:nil];

    [self.view addSubview:music.view];

    [music release];    
}

      

When you click a button in the view, the idea is to load another newbie, MusicPick, which will load as a subtitle, select something and come back here. Any help is appreciated, or new ideas.

+1


a source to share


2 answers


To add a little more detail.

You can add a view to an existing UIViewController using addSubView or by clicking the controller on the UITabBarController view. In the latter case, the UITabBarController must [was] a UINavigationController with a RootViewController.

I suspect this is what you mean. So you would do something like the following.



- (IBAction)PlaylistButtonPressed:(id)sender
{
    // Load UIViewController from nib
    MusicPick *music = [[MusicPick alloc] initWithNibName:@"MusicPick" bundle:nil];

    // Add to UINavigationController stack, i.e. the view for this UITabBarController view
    [self.navController pushViewController:music animated:YES];

    // Release music, no longer needed since it is retained by the navController
    [music release];   
}

      

This assumes you have a UINavigationController in your UITabBarController and it is called navController.

If you just want to add a UIView to a UIViewController view in a UITabBarController (like an overlay) then you can just use addSubView, as you already figured out, no UINavigation Controller is required.

+1


a source


You cannot add subview directly to UITabBarController

. The way one of these controllers works is to save a list UIViewController

and display each one in a tab. But they really defy consideration, for sé. You don't change the tab bar controller itself at all, other than updating this list.



As it seems to you what you need to do, this is a temporary view allowing the user to select some options that will affect something in the tab bar controller. I would suggest that you present this view from your nib as a tabbed modal view. Take a look at UIViewController

presentModalViewController:animated:

and dismissModalViewControllerAnimated:

. Assuming it MusicPick

is a subclass UIViewController

, just pass it to that method after it has been allocated (like you did in the first line of code above) and UIKit will take care of the rest. Remember to free this instance MusicPick

when you finish pulling selected values ​​or user-entered data from it.

+3


a source







All Articles