1

我想在Push我的 viewController 上PresentViewController

当我最初单击按钮时,我正在加载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我想推送我的视图,但不推送。

请帮助,在此先感谢。

4

2 回答 2

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

尝试像这样推送 viewController。如果您在AppDelegate中使用 TabBar,请这样做。如果您创建 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;
}

我希望你现在得到

于 2013-10-30T06:48:24.870 回答
1

pushviewcontrollerUINavigationController的功能,您可以在其中将一个 viewcontroller 推送到另一个 vierw 控制器上。在这里,您使用单个 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

第一视图控制器.h

-(void) nextBtnPressed {
    SecondViewController *second = [[SecondViewController alloc]  initWithNibName:@"SecondViewController" bundle:nil];
     [self.navigationController pushViewController:second animated:TRUE];
 }
于 2013-10-30T06:49:42.137 回答