从初始视图控制器上的uinavigation栏上的PushViewController和Popview Controller

时间:2012-07-20 10:07:47

标签: iphone ios

我是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无法正常工作。如果有人知道这个,请帮助我..

2 个答案:

答案 0 :(得分: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];
}

答案 1 :(得分: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];