在PresentViewController iOS上的PushView

时间:2013-10-30 06:42:51

标签: ios presentmodalviewcontroller pushviewcontroller

我希望在Push

PresentViewController我的viewController

当我点击按钮时,我正在加载PresentViewController,这是我的代码。

- (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];

}

这个工作正常,但是当我点击PresentViewController点击按钮时,我想推送我的视图,但是不推动。

请提供帮助,提前致谢。

2 个答案:

答案 0 :(得分:2)

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

尝试这样推送viewController。如果您使用TabBar,请在 AppDelegate 中执行此操作。如果你创建TabBar拖放意味着离开。以编程方式创建TabBar,如下所示。

- (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;
}

我希望你现在有了

答案 1 :(得分:1)

pushviewcontroller UINavigationController 的功能,您可以在另一个vierw控制器上推送一个viewcontroller。在这里,您使用单个viewcontroller作为rootviewcontroller,因此您必须将 rootviewcontroller 更改为 UINavigationcontroller ,或者您可以使用“ addSubview方法”来添加当前viewcontroller上的新viewController。

但更好的选择是将 uinavigationcontroller 添加为 rootviewcontroller

  

AppDelegate.m

     

- (BOOL)应用程序:(UIApplication *)应用程序didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

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

}

现在当你想要从按下按钮切换到FirstViewController到SecondViewController时,你必须使用pushviewcontroller

  

FirstViewController.h

-(void) nextBtnPressed {
    SecondViewController *second = [[SecondViewController alloc]  initWithNibName:@"SecondViewController" bundle:nil];
     [self.navigationController pushViewController:second animated:TRUE];
 }