Tab bar in view based application?

2020-03-30 06:28发布

问题:

I am new to iphone development.I have created a view based application.Now i want tab bar in that view.The first view of the tab bar is a table view and the second view is the Web-view.All the tutorials explain only tab bar based application.Since i am using view based application i finding it really hard.How to achieve it by using interface builder.please guide me.Any Sample tutorials will be more useful.Please help me out.Thanks.

回答1:

Try this one. This code for created a tab bar application in programmatically. So clicked the button it will open the tab bar in the view.

   -(IBAction) clkBtn:(id) sender
   { 

    UITabBarController *tabbar1 = [[UITabBarController alloc] init];

    firstViewController  *first = [[firstViewController alloc] initWithNibName:@"firstViewController" bundle:nil];

    UINavigationController *tabItem1 = [[[UINavigationController alloc] initWithRootViewController: first] autorelease];

    secondViewController  *second = [[secondViewController alloc] initWithNibName:@"secondViewController" bundle:nil];

    UINavigationController *tabItem2 = [[[UINavigationController alloc] initWithRootViewController: second] autorelease];

    tabbar1.viewControllers = [NSArray arrayWithObjects:tabItem1, tabItem2,nil]; 

    [self.view insertSubview:tabbar1.view belowSubview: first.view];

    [self presentModalViewController:tabbar1 animated:YES];

  }

Thanks,

Best of Luck.