How to change between controllers when button tapped , iOS? - objective-c

So i have my main viewController and all i have is a single button inside.
The code of the button is :
- (IBAction)eventsButton:(id)sender {
self.eventsViewController =[[EventsViewController alloc]initWithNibName:#"EventsViewController" bundle:nil];
[self.navigationController pushViewController:eventsViewController animated:YES];}
where EventsViewController is another controller where i want to navigate when this button is clicked. But when i click it nothing happens.. I dont navigate to the other controller.
ViewController.h
-------------------
#import <UIKit/UIKit.h>
#class EventsViewController;
#interface ViewController : UIViewController <UIActionSheetDelegate>
- (IBAction)eventsButton:(id)sender;
#property (strong, nonatomic) EventsViewController *eventsViewController;
#end
ViewController.m
-----------------
#import "ViewController.h"
#import "EventsViewController.h"
#implementation ViewController
#synthesize eventsViewController;
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Release any cached data, images, etc that aren't in use.
}
#pragma mark - View lifecycle
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
- (void)viewDidUnload
{
[super viewDidUnload];
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
}
- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
}
- (void)viewWillDisappear:(BOOL)animated
{
[super viewWillDisappear:animated];
}
- (void)viewDidDisappear:(BOOL)animated
{
[super viewDidDisappear:animated];
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations
return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
}
- (IBAction)eventsButton:(id)sender {
self.eventsViewController =[[EventsViewController alloc]initWithNibName:#"EventsViewController" bundle:nil];
[self.navigationController pushViewController:eventsViewController animated:YES];
}
#end
I put a breakpoint in the IBACTION and i see that the code is executed , but it never navigates me to the other controller. The other controller is just a simple controller i created with Xcode , it has all the code Xcode gives and nothing mine.
Any ideas?

My guess is you didn't put ViewController inside UINavigationController. First you have to alloc and init UINavigationController. So inside application: didFinishLounchingWithOptions:
ViewController *viewController = [[ViewController alloc] init];
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:viewController]
[self.window setRootViewController:navigationController];
[self.window makeKeyAndVisible]
It should work.

[self.navigationController pushViewController:eventsViewController animated:YES];
its works only current view controller is navigation controller.Actually you implement this code in normal view controller not in navigation controller. Check with this following code replace above line
[self presentModalViewController:eventsViewController animated:YES];
So You need to implement navigation controller for your current view controller. In Appdelegate you change root view controller to navigation controller with your view controller.
UINavigationController *navController = [[[UINavigationController alloc] initWithRootViewController:yourController] autorelease];
self.window.rootViewController = navController;

Related

iOS 7: Custom container view controller with UINavigationController as a child view controller

I would like to write a custom full-screen container view controller with the intention of putting a UINavigationController in it as a child view controller. The view of the UINavigationController will fill up the view of the container view controller so that it looks like the UINavigationController is the root view controller. (One would want to do something like this to, say, create the sliding sidebar menu UI popularized by Facebook.)
What I've done works EXCEPT there is a glitch when presenting another view controller that hides the status bar when the iPhone is in landscape orientation. Typically, the navigation bar slides up when the status bar disappears and slides down when it reappears. Instead, the navigation bar stays where it is when it is suppose to slide up, and when it is suppose to slide down, it is first positioned with the status bar overlapping it and then jumps to its correct position below the status bar. Basically, I'm trying to have the UINavigationController behave as it would if it were not inside a custom container view controller.
Below is some code that you can run to see the problem, but if you don't want to do that, just take a look at the ContainerViewController class, which implements a minimal custom container view controller. What is it that I'm missing in my custom container view controller that is causing this problem? It works when I use a UITabBarController as the container view controller, so it seems like I'm just missing something in my implementation.
MORE STUFF BELOW TO READ IF YOU WANT
If you would like to run the sample code to see the problem, here is an overview. There is a preprocessor definition called MODE defined in AppDelegate to conditionally compile the app in three ways.
When MODE == 1, ViewController is inside a UINavigationController. You can then press a "Present" button to present ViewControllerWithStatusBarHidden, and then you can press a "Dismiss" button to dismiss this view controller. This mode of the app shows the behavior that I am seeking.
When MODE == 2, we have the same thing as in MODE == 1 except that the UINavigationController is inside of a ContainerViewController. This mode of the app shows the undesirable behavior I have currently.
When MODE == 3, we have the same thing as in MODE == 1 except that the UINavigationController is inside of a UITabBarController. This mode of the app shows that it is possible to get the behavior I am seeking.
Again, to see the problem, just press the "Present" button and then the "Dismiss" button when the iPhone is in landscape orientation.
CODE
Four classes:
ContainerViewController
AppDelegate
ViewController
ViewControllerWithStatusBarHidden
ContainerViewController.h
#import <UIKit/UIKit.h>
#interface ContainerViewController : UIViewController
#property (nonatomic) UIViewController * viewController;
#end
ContainerViewController.m
#import "ContainerViewController.h"
// This custom container view controller only has one child view controller,
// whose view fills up the view of the container view controller.
#implementation ContainerViewController
- (UIViewController *)viewController {
if (self.childViewControllers.count > 0) {
return [self.childViewControllers firstObject];
}
else {
return nil;
}
}
- (void)setViewController:(UIViewController *)viewController {
UIViewController *previousViewController = [self.childViewControllers firstObject];
if ((previousViewController == nil && viewController != nil)
|| (previousViewController != nil && viewController == nil)
|| (previousViewController != nil && viewController != nil
&& previousViewController != viewController))
{
if (previousViewController != nil) {
// Remove the old child view controller.
[previousViewController willMoveToParentViewController:nil];
[previousViewController.view removeFromSuperview];
[previousViewController removeFromParentViewController];
}
if (viewController != nil) {
// Add the new child view controller.
[self addChildViewController:viewController];
self.viewController.view.frame = self.view.bounds;
self.viewController.view.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
[self.view addSubview:self.viewController.view];
[self.viewController didMoveToParentViewController:self];
}
}
}
- (UIViewController *)childViewControllerForStatusBarHidden {
return self.viewController;
}
- (UIViewController *)childViewControllerForStatusBarStyle {
return self.viewController;
}
#end
AppDelegate.h
#import <UIKit/UIKit.h>
#interface AppDelegate : UIResponder <UIApplicationDelegate>
#property (strong, nonatomic) UIWindow *window;
#end
AppDelegate.m
#import "AppDelegate.h"
#import "ViewController.h"
#import "ContainerViewController.h"
#define MODE 2 // Mode can be 1, 2, or 3.
#implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
ViewController *vc = [[ViewController alloc] initWithNibName:nil bundle:nil];
UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:vc];
#if MODE == 1 // No container view controller.
self.window.rootViewController = nav;
#elif MODE == 2 // Use custom container view controller.
ContainerViewController *container = [[ContainerViewController alloc] initWithNibName:nil bundle:nil];
container.viewController = nav;
self.window.rootViewController = container;
#elif MODE == 3 // Use tab bar controller as container view controller.
UITabBarController *tab = [[UITabBarController alloc] initWithNibName:nil bundle:nil];
tab.viewControllers = #[nav];
self.window.rootViewController = tab;
#endif
[self.window makeKeyAndVisible];
return YES;
}
#end
ViewController.h
#import <UIKit/UIKit.h>
#interface ViewController : UIViewController
#end
ViewController.m
#import "ViewController.h"
#import "ViewControllerWithStatusBarHidden.h"
// This view controller will serve as the content of a navigation controller.
// It also provides a button in the navigation bar to present another view controller.
#implementation ViewController
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
self.title = #"Title";
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:#"Present"
style:UIBarButtonItemStylePlain
target:self
action:#selector(pressedPresentButton:)];
}
return self;
}
- (void)loadView {
self.view = [[UIView alloc] init];
self.view.backgroundColor = [UIColor whiteColor];
}
- (void)pressedPresentButton:(id)sender {
ViewControllerWithStatusBarHidden *vc = [[ViewControllerWithStatusBarHidden alloc] initWithNibName:nil bundle:nil];
[self presentViewController:vc animated:YES completion:nil];
}
#end
ViewControllerWithStatusBarHidden.h
#import <UIKit/UIKit.h>
#interface ViewControllerWithStatusBarHidden : UIViewController
#end
ViewControllerWithStatusBarHidden.m
#import "ViewControllerWithStatusBarHidden.h"
// This view controller is meant to be presented and does two things:
// (1) shows a button to dismiss itself and (2) hides the status bar.
#implementation ViewControllerWithStatusBarHidden
- (void)loadView {
self.view = [[UIView alloc] init];
self.view.backgroundColor = [UIColor yellowColor];
}
- (void)viewDidLoad {
[super viewDidLoad];
UIButton *dismissButton = [UIButton buttonWithType:UIButtonTypeSystem];
[dismissButton setTitle:#"Dismiss" forState:UIControlStateNormal];
[dismissButton addTarget:self
action:#selector(pressedDismissButton:)
forControlEvents:UIControlEventTouchUpInside];
dismissButton.frame = CGRectMake(100, 100, 100, 100);
[self.view addSubview:dismissButton];
}
- (void)pressedDismissButton:(id)sender {
[self.presentingViewController dismissViewControllerAnimated:YES completion:nil];
}
- (BOOL)prefersStatusBarHidden {
return YES;
}
//- (NSUInteger)supportedInterfaceOrientations {
// return UIInterfaceOrientationMaskPortrait;
//}
#end

Upside down Orientation issue in iOS6

I am creating a sample empty application and added UIViewController class,
Below is the code in the App delgate
TestViewController* viewController = [[TestViewController alloc] initWithNibName:#"TestViewController" bundle:nil];
UINavigationController* navController = [[UINavigationController alloc] initWithRootViewController:viewController];
[self.window setRootViewController:navController];
Now i am rotating the App but in the UPsidedown Orientation Navigation bar is not Rotating I am attaching a screen shot
Then Added a the Below Method in App delegate
- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window{
return UIInterfaceOrientationMaskAll;
}
And in the Class i have added following methods
-(BOOL)shouldAutorotate
{
return YES;
}
- (NSUInteger)supportedInterfaceOrientations
{
return (UIInterfaceOrientationMaskAll);
}
In the Summary i have activated all the orientations can any One tell me the Solution for it
1) just You created a category for UINavigationController class and I defined these methods
In CustomViewController.h
#import <UIKit/UIKit.h>
#interface CustomViewController : UINavigationController
#end
In CustomViewController.m
#import "CustomViewController.h"
#interface CustomViewController ()
#end
#implementation CustomViewController
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
-(BOOL) shouldAutorotate{
return YES;
}
-(NSUInteger) supportedInterfaceOrientations{
return UIInterfaceOrientationMaskAll;
}
And AppDelgate.m file
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.viewController = [[ViewController alloc] initWithNibName:#"ViewController" bundle:nil];
CustomViewController *navController = [[CustomViewController alloc] initWithRootViewController:self.viewController];
// Override point for customization after application launch.
self.window.rootViewController = navController;
[self.window makeKeyAndVisible];
return YES;
}
2) And check Orientation In Target
3) Change the class from UINavigationController to the CustomViewController in my XIB in IB
4) Reset the Simulator and run the code, I think your problem will be solve.
i think you need to use
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return TRUE;
}
instead of shouldAutorotate
Upside Down button to ON in Supported interface orientations on Xcode
http://www.appcoda.com/ios-game-tutorial-maze-part-1/
`TestViewController* viewController = [[TestViewController alloc] initWithNibName:#"TestViewController" bundle:nil];
[self.window setRootViewController:viewController];`
remove the navigatioan bar from appdelegate and then check

Custom delegate iOS 6 using ARC not working

I am a begginer with Objective-C programming.
I searched here and in other websites to a way to solve my problem but i did not find.
I want to create an login view before the system load. Then, after login i want to dismiss it.
On my project i use ARC and not use Storyboards.
When i debug and look into the function "efetuarLogin" the value of property delegate is 0x000000. I think it is blank, is not?
According to the tutorials and other tips i found on the internet, this is the right way to code delegate. Can you check this for me?
Here is the code:
Login.h
#import <UIKit/UIKit.h>
#class Login;
#protocol LoginDelegate <NSObject>
#required
- (void)loginDidFinish: (Login *)login;
#end
#interface Login : UIViewController{
__weak id<LoginDelegate> delegate;
}
#property (nonatomic, weak) id <LoginDelegate> delegate;
- (IBAction)efetuarLogin:(id)sender;
#end
Login.M
#import "Login.h"
#implementation Login
#synthesize delegate;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (IBAction)efetuarLogin:(id)sender {
[delegate loginDidFinish:self];
}
#end
MainController.h
#import <UIKit/UIKit.h>
#import "Login.h"
#interface MainController : UITabBarController <LoginDelegate>
#end
MainController.m
#import "MainController.h"
#import "Login.h"
#import "ModalViews.h"
#import "Alerts.h"
#import "ViewPadrao.h"
#import "TableView.h"
#implementation MainController
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
ModalViews *modalViews = [[ModalViews alloc] initWithNibName:#"ModalViews" bundle:nil];
Alerts *alerts = [[Alerts alloc] initWithNibName:#"Alerts" bundle:nil];
ViewPadrao *viewPadrao = [[ViewPadrao alloc] initWithNibName:#"ViewPadrao" bundle:nil];
TableView *tableView = [[TableView alloc] initWithNibName:#"TableView" bundle:nil];
self.viewControllers = #[modalViews, alerts, viewPadrao, tableView];
}
- (void)viewDidAppear:(BOOL)animated{
[super viewDidAppear:animated];
Login *login = [[Login alloc] initWithNibName:#"Login" bundle:nil];
[login setModalTransitionStyle:UIModalTransitionStyleCoverVertical];
[self presentViewController:login animated:NO completion:nil];
}
- (void)loginDidFinish: (Login *)login{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Sua mensagem aqui" message:#"Mensagem" delegate:self cancelButtonTitle:#"Fechar" otherButtonTitles:nil];
[alert show];
[self dismissViewControllerAnimated:YES completion:nil];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#end
And the method didFinishLaunchingOptions of AppDelegate.m:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
mainController = [[MainController alloc] init];
window.rootViewController = mainController;
[window makeKeyAndVisible];
return YES;
}
Sorry for the high quantity of code. I am thankful since already!!
I am using the ViewDidAppear method to show Login to users. But when i dismiss and the MainController appears, the method viewdidapper creates the Login again.
How i do to show login once? When i tried to do this on viewdidload it did not work. The login did not appear.
In your MainViewController.m when you create login object
- (void)viewDidAppear:(BOOL)animated{
[super viewDidAppear:animated];
Login *login = [[Login alloc] initWithNibName:#"Login" bundle:nil];
login.delegate = self; //add this line
[login setModalTransitionStyle:UIModalTransitionStyleCoverVertical];
[self presentViewController:login animated:NO completion:nil];
}
EDIT : After seeing OP's edit in the question (which should have been a different thread)
Your view Controller hierarchy is wrong. The ideal flow should be
1) Show Login controller directly from App delegate.
2) After successfull login, show MainViewController from Login Controller.

Can't override a simple method

I've created a new project with two ViewControllers and imported a class that pushes ViewController from right to left instead LTR but can't manage to use it. I can see that pushViewController inside UIRightToLeft.m is not being called and I don't understand why.
My main goal is to get that working with RTL aniamtion.
#import "UIRightToLeft.h"
#implementation UIRightToLeft
- (id)initWithRootViewController:(UIViewController *)rootViewController
{
self = [super initWithRootViewController:rootViewController];
if (!self)
return nil;
return self;
}
- (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated
{
NSLog(#"pushViewController");
// Add the viewController and a fake controller without animation. Then pop the fake controller with animation.
UIViewController *fakeController = [[UIViewController alloc] init] ;
[super setViewControllers:[[self viewControllers] arrayByAddingObjectsFromArray:[NSArray arrayWithObjects:viewController, fakeController, nil]] animated:NO];
[super popViewControllerAnimated:animated];
}
- (void)popViewControllerAnimatedStep2:(UIViewController *)viewController
{
// Push the new top controller with animation
[super pushViewController:viewController animated:YES];
// Remove the view that should have been popped
NSMutableArray *arr = [NSMutableArray arrayWithArray:[self viewControllers]];
[arr removeObjectAtIndex:[[self viewControllers] count]-2];
[super setViewControllers:[NSArray arrayWithArray:arr] animated:NO];
}
- (UIViewController *)popViewControllerAnimated:(BOOL)animated
{
NSLog(#"popViewControllerAnimated");
if (animated)
{
// Save the controller that should be on top after this pop operation
UIViewController *newTopController = [[self viewControllers] objectAtIndex:[[self viewControllers] count]-2];
// Remove it from the stack. Leave the view that should be popped on top
NSMutableArray *arr = [NSMutableArray arrayWithArray:[self viewControllers]];
[arr removeObjectAtIndex:[[self viewControllers] count]-2];
[super setViewControllers:[NSArray arrayWithArray:arr] animated:NO];
// Schedule the next step
[self performSelector:#selector(popViewControllerAnimatedStep2:) withObject:newTopController afterDelay:0];
return [arr objectAtIndex:[arr count]-1];
}
return [super popViewControllerAnimated:NO];
}
#end
ViewController.m:
#import "ViewController.h"
#import "UIRightToLeft.h"
#import "SecondViewController.h"
#interface ViewController ()
#end
#implementation ViewController
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (IBAction)pressMe:(UIButton *)sender {
SecondViewController *next = [[SecondViewController alloc]init];
[self.navigationController pushViewController:next animated:YES];
}
#end
ViewController.h:
#import <UIKit/UIKit.h>
#interface ViewController : UIViewController
- (IBAction)pressMe:(UIButton *)sender;
#end
(In my ViewController there's only one button draged to the second ViewController with push)
After looking at your error log I think you actually need to have your navigation controller subclass UIRightToLeft.
If you are using a Storyboard, select your navigation controller and set Custom Class to UIRightToLeft.

How to put a tab bar only in certain place in the app?

I want to put a tab bar for one place in my app. From there i can load some other view controllers, but that's it. I don't want it for my whole application. All examples I read through are making the tab bar controller as the rootviewcontroller of the window.
So how do i do that?
Thank you!
his may help you, Consider your view controller is HomeView where from you are going to push a tab bar controller, The HomeView is loaded in view at below:
#import "AppDelegate.h"
#implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
HomeView *homeview = [[HomeView alloc] initWithNibName:#"HomeView" bundle:nil];
UINavigationController *navigation = [[UINavigationController alloc] initWithRootViewController:homeview];
self.window.rootViewController = navigation;
[self.window makeKeyAndVisible];
return YES;
}
#end
then the .h, .m and .xib files of HomeView are going to be as follows:
In HomeView.h
#import <UIKit/UIKit.h>
#interface HomeView : UIViewController
{
IBOutlet UITabBarController *tabBarController;
}
-(IBAction)loadTabBar:(id)sender;
#end
and the HomeView.m is:
#implementation HomeView
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
-(IBAction)loadTabBar:(id)sender
{
[self.navigationController pushViewController:tabBarController animated:YES];
}
- (void)didReceiveMemoryWarning
{
// Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];
// Release any cached data, images, etc that aren't in use.
}
#pragma mark - View lifecycle
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
}
- (void)viewDidUnload
{
[super viewDidUnload];
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
#end
and the .xib file must be as follows:
The tabBarController IBOutlet must be connected to the UITabBarController that on the .xib file. And that UITabBarController with two view controllers named FirstViewController, SecondViewController. Moreover that the HomeView must be inside a UINavigationController.
If not clarified with this answer, I'll update with detailed explanation.
The above is a way of loading tab bar controller using XIB method.
You can do this by coding like below by changing something in IBAction(button action) , In HomeView.m file:
#import "HomeView.h"
#import "FirstViewController.h"
#import "SecondViewController.h"
#implementation HomeView
-(IBAction)loadTabBar:(id)sender
{
FirstViewController *firstView = [[FirstViewController alloc] initWithNibName:#"FirstViewController" bundle:nil];
SecondViewController *secondView = [[SecondViewController alloc] initWithNibName:#"SecondViewController" bundle:nil];
tabBarController = [[UITabBarController alloc] init];
tabBarController.viewControllers = [NSArray arrayWithObjects:firstView, secondView, nil];
[self.navigationController pushViewController:tabBarController animated:YES];
}
#end
You have to make tabBar in app delegate and then add when ever you want using this
-(void)addTabBarController
{
AppDelegate *appdelegte =(AppDelegate*)[[UIApplication sharedApplication]delegate];
//[[[appdelegte navigationController] view]removeFromSuperview];
[[appdelegte window]addSubview:[[appdelegte tabcontroller]view]];
[[appdelegte tabcontroller]setSelectedIndex:0];
}