0

我是 iPhone 新手。我对 uinavigation 控制器有一点困惑,即我希望在该视图控制器中的初始视图控制器中有一个导航栏,当我们单击时,导航栏中有一个按钮,它将从那里推送另一个视图控制器(第二个视图控制器)是一个后退按钮,如果我们单击我想弹出该视图控制器并返回到初始视图控制器。如果有人知道这一点,请帮助我。如果你用一些代码解释它会更好地理解我们。

我写的以下代码,到目前为止,这里存在模态视图控制器和关闭模型视图控制器正在工作,但 pushview 控制器和 popview 控制器不工作

在 appDelegate 我这样写

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
        //create a window
        self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];

        //biblePlayerController is an instance of BiblePlayerViewController class and then set the biblePlayerController as a rootViewController to the window
        self.biblePlayerController = [[BiblePlayerViewController alloc] initWithNibName:@"BiblePlayerViewController" bundle:nil];

       navigationController = [[UINavigationController alloc]initWithRootViewController:self.biblePlayerController];

      // self.window.rootViewController = self.biblePlayerController;
        [self.window addSubview:navigationController.view];  
//make the window visible
        [self.window makeKeyAndVisible];

        return YES;   

}   

//In initial View controller there is a navigation on that there is a download button code for that is 

//BiblePlayerViewController.m
 UIBarButtonItem *downloadButton = [[UIBarButtonItem alloc] initWithTitle:@"Download" style:UIBarButtonItemStylePlain target:self action:@selector(gotoProgressViewController:)];
        self.navigationItem.rightBarButtonItem = downloadButton;

- (IBAction)gotoProgressViewController:(id)sender {
    @try {

        //ShowProgressViewCont is initialized with the nibName
        showProgressViewController = [[ShowProgressViewCont alloc]initWithNibName:@"ShowProgressViewCont" bundle:nil];

        //UINavigationController is initialized with the rootViewController showProgressViewController
        navigationController = [[UINavigationController alloc]initWithRootViewController:showProgressViewController]; 

        //The transition style of the navigationController is set to UIModalTransitionStyleCrossDissolve
        navigationController.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;

        //Presents a modal view managed by the given view controller to the user.Here navigation Controller that manages the modal view.
        [self presentModalViewController:navigationController animated:YES];
      //  [navigationController pushViewController:showProgressViewController animated:YES];
    }
    @catch(NSException * e){NSLog(@"Exception At10: %s %d %s %s %@",__FILE__,__LINE__,__PRETTY_FUNCTION__,__FUNCTION__,e);}@finally{}
}

在上面的代码中,presentModalViewController 可以正常工作,但 pushViewController 不能正常工作。如果有人知道这一点,请帮助我..

4

2 回答 2

0

假设您在 ParentViewController 中,并且通过按 Child Btn 您想转到 ChildViewController。

- (void) childBtnPressed : (id) sender
{
     ChildViewController *makeNewObject = [[ChildViewController alloc] initWithNibName:@"ChildViewController" bundle:nil];
     [self.navigationController pushViewController:makeNewObject animated:YES];
     [makeNewObject release];
}

现在在您的 ChildViewController.m 文件中,将其写入 Back Btn 操作以返回父视图控制器。

- (void) backBtnPressed : (id) sender
{
    [self.navigationController popViewControllerAnimated:YES];
}
于 2012-07-20T10:30:53.830 回答
0

单击导航栏中的按钮时,推送下一个视图

- (IBAction)NextViewAction:(id) sender
{
     NextViewController *NxtView = [[NextViewController alloc] initWithNibName:@"NextViewController" bundle:nil];
     [self.navigationController pushViewController:NxtView animated:YES];
     [NxtView release];
}

从 NextViewController 弹出

[self.navigationController popViewControllerAnimated:YES];
于 2012-07-20T10:52:51.803 回答