开发者

Having a UITabBar while displaying a view not on the UITabBar?

I have been having some trouble with the UITabBar and cannot find anything online in regards to the subject. Pretty much I want to display a view (say TestView) and a TabBar that contains to other views: Green View and Red View. So initially I want TestView displayed with a tabBar on the botto开发者_开发技巧m with 2 tabs, one for Green view and one for Red View, once one of those tabs are touched the appropriate view will be displayed, but there will be no tab for the TestView

But heres the MainAppDelegate code and a picture of what I get

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {    

//Create the TabBar VC and ButtonSelect VC
testView = [[TestViewController alloc] init];
tabBarController = [[UITabBarController alloc] init];

//Create the viewcontroller's For the TabBarController
UIViewController *gvc = [[GreenViewController alloc] init];
UIViewController *rvc = [[RedViewController alloc] init];

//Make a array to containing the two viewcontrollers (for TabBar)
NSArray *viewControllers = [NSArray arrayWithObjects:gvc, rvc, nil];

//Attach the VC's to the TabBar
[tabBarController setViewControllers:viewControllers];

//Set to window
[window addSubview:[tabBarController view]];
[window addSubview:[testView view]];


[window makeKeyAndVisible];

[rvc release];
[gvc release];

return YES;

}

And This is what I get..

Please help


Adjust the frame of your testView. For example,

testView = [[TestViewController alloc] initWithFrame: CGRectMake( 0.0, 20.0, 320.0, 421.0)];

I used "magic numbers" here, but you had better get the height of the status bar and tab bar.


to the comment

So you want to dismiss the test view when the user selects one of the tab. You can catch the moment when a tab is selected by setting a delegate to the UITabBarController and implement tabBarController:didSelectViewController:` method. Basically, you will dismiss the test view in this method.

One way of doing it (and without changing your code much) is to set your application delegate as the delegate of the UITabBarController, (tabBarController.delegate = self;). Then implement tabBarController:didSelectViewController:, where you remove the test view from your application window and do tabBarController.delegate = nil;.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜