Question

I want to Push my viewController on PresentViewController

When i click on button initially i am loading PresentViewController, here is my code.

- (IBAction)JoinClicked:(id)sender{

    JoinWithViewController *detail_view_controller = [[JoinWithViewController alloc] initWithNibName:@"JoinWithViewController" bundle:nil];
    [self.view.window.rootViewController presentViewController:detail_view_controller
                                                      animated:YES
                                                    completion:NULL];

}

this works fine, but when i click on button which is there on PresentViewController on click i want to Push my view, but in does not pushes.

Please help, Thanks in advance.

Was it helpful?

Solution

JoinWithViewController *detail_view_controller = [[JoinWithViewController alloc] initWithNibName:@"JoinWithViewController" bundle:nil];
[self.navigationController pushViewController:detail_view_controller animated:YES];

Try like this to push viewController. If you use TabBar do like this in AppDelegate. If you create TabBar Drag and drop means leave that. Create TabBar Programatically like below.

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    // Override point for customization after application launch.
    UITabBarController *tabController = [[UITabBarController alloc]init];

    self.viewController = [[CalculatorViewController alloc] initWithNibName:@"CalculatorViewController" bundle:nil];
    UITabBarItem *tab_item1 = [[UITabBarItem alloc]init];
    //tab_item1.title = @"Calculator";
    tab_item1.image = [UIImage imageNamed:@"Calculator.png"];
    [self.viewController setTabBarItem:tab_item1];
    UINavigationController *nav1 = [[UINavigationController alloc]initWithRootViewController:self.viewController];

    ShowPhoneViewController *phone = [[ShowPhoneViewController alloc]init];
    UITabBarItem *tab_item2 = [[UITabBarItem alloc]init];
    tab_item2.title = @"Latest Mobiles";
    tab_item2.image = [UIImage imageNamed:@"Mobile.png"];
    [phone setTabBarItem:tab_item2];
    UINavigationController *nav2 = [[UINavigationController alloc]initWithRootViewController:phone];

    CurrencyConvertorViewController *currency = [[CurrencyConvertorViewController alloc]init];
    UITabBarItem *tab_item3 = [[UITabBarItem alloc]init];
    tab_item3.title = @"Units Convertor";
    tab_item3.image = [UIImage imageNamed:@"Dollar.png"];
    [currency setTabBarItem:tab_item3];
    UINavigationController *nav3 = [[UINavigationController alloc]initWithRootViewController:currency];

    SettingsPageViewController *setting = [[SettingsPageViewController alloc]init];
    UITabBarItem *tab_item4 = [[UITabBarItem alloc]init];
    tab_item4.title = @"Settings";
    tab_item4.image = [UIImage imageNamed:@"Settings.png"];
    [setting setTabBarItem:tab_item4];
    UINavigationController *nav4 = [[UINavigationController alloc]initWithRootViewController:setting];


    tabController.viewControllers = [NSArray arrayWithObjects:nav1, nav2, nav3, nav4, nil];
    self.window.rootViewController = tabController;

    [self.window makeKeyAndVisible];
    return YES;
}

I hope you got now

OTHER TIPS

pushviewcontroller is the feature of UINavigationController where you can push one viewcontroller on another vierw controller. Here you are using a single viewcontroller as a rootviewcontroller so either you must change your rootviewcontroller to UINavigationcontroller or you can use "addSubview method" to add new viewController on the current viewcontroller.

but the better option is to add uinavigationcontroller as a rootviewcontroller.

AppDelegate.m

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

     FirstViewController *first = [[FirstViewController alloc]
                                 initWithNibName:@"FirstViewController" bundle:nil];
     UINavigationController *navController =[[UINavigationController alloc] 
                                            initWithRootViewController:first];
     [self.window setRootViewController:navController];   

}

Now when as you want to switch from FirstViewController to SecondViewController on button clicked than you have to use pushviewcontroller

FirstViewController.h

-(void) nextBtnPressed {
    SecondViewController *second = [[SecondViewController alloc]  initWithNibName:@"SecondViewController" bundle:nil];
     [self.navigationController pushViewController:second animated:TRUE];
 }
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top