我是 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 不能正常工作。如果有人知道这一点,请帮助我..