Iphone 来自初始视图控制器的导航栏上的PushViewController和Popview控制器
我不熟悉iphone。我对uinavigation控制器有一点困惑,那就是我希望在初始视图控制器中有一个导航栏在该视图控制器中,当我们单击导航栏上的一个按钮时,它将按下另一个视图控制器(第二个视图控制器)如果我们点击这个按钮,就会有一个后退按钮,我想弹出那个视图控制器,然后回到初始视图控制器。如果有人知道这一点,请帮助我。如果你用一些代码解释的话,会更好地理解我们 到目前为止,我已经编写了以下代码,其中显示模式视图控制器和模型视图控制器正在工作,但pushview控制器和popview控制器不工作 在appDelegate中,我是这样写的Iphone 来自初始视图控制器的导航栏上的PushViewController和Popview控制器,iphone,ios,Iphone,Ios,我不熟悉iphone。我对uinavigation控制器有一点困惑,那就是我希望在初始视图控制器中有一个导航栏在该视图控制器中,当我们单击导航栏上的一个按钮时,它将按下另一个视图控制器(第二个视图控制器)如果我们点击这个按钮,就会有一个后退按钮,我想弹出那个视图控制器,然后回到初始视图控制器。如果有人知道这一点,请帮助我。如果你用一些代码解释的话,会更好地理解我们 到目前为止,我已经编写了以下代码,其中显示模式视图控制器和模型视图控制器正在工作,但pushview控制器和popview控制器不工
- (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不工作。为什么。如果有人知道这一点,请帮助我。假设您在ParentViewController中,通过按Child Btn,您希望转到ChildViewController
- (void) childBtnPressed : (id) sender
{
ChildViewController *makeNewObject = [[ChildViewController alloc] initWithNibName:@"ChildViewController" bundle:nil];
[self.navigationController pushViewController:makeNewObject animated:YES];
[makeNewObject release];
}
- (void) backBtnPressed : (id) sender
{
[self.navigationController popViewControllerAnimated:YES];
}
现在,在ChildViewController.m文件中,在Back Btn操作中写入此命令,以返回到父视图控制器
- (void) childBtnPressed : (id) sender
{
ChildViewController *makeNewObject = [[ChildViewController alloc] initWithNibName:@"ChildViewController" bundle:nil];
[self.navigationController pushViewController:makeNewObject animated:YES];
[makeNewObject release];
}
- (void) backBtnPressed : (id) sender
{
[self.navigationController popViewControllerAnimated:YES];
}
单击导航栏中的按钮后,按Next View
- (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];