iphone sdk 中的导航错误
大家好,我在我的应用程序中的一个视图控制器中遇到了问题。
我正在开发一个圣经应用程序,其中包含书籍选择页面,然后是章节选择,然后是经文选择,其架构是,当用户单击 bookviewcontroller 中的任何书籍按钮时,它将导航到相应书籍的章节选择页面,然后用户选择其中之一章节按钮它会重定向到相应的章节页面。
一切对我来说都很好,但我的问题是这些页面中没有发生后退导航操作。章节选择和诗句选择页面中有后退按钮,但导航返回不起作用,我尝试了很多解决此错误但没有用,我的导航代码是:
这是书籍选择中的章节选择重定向代码 -
-(void)ButtonClicked:(UIButton *)sender{
ChapterSelectionView *chapterSelectionView=[[ChapterSelectionView alloc]initWithNibName:@"ChapterSelectionView" bundle:nil];
chapterSelectionView.selectedIndex=sender.tag;
appDelegate.selectedBookIndex=sender.tag;
self.hidesBottomBarWhenPushed=YES;
chapterSelectionView.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
[self presentModalViewController:chapterSelectionView animated:YES];
[UIView commitAnimations];
[chapterSelectionView release];
}
这是重定向到诗句页面代码 -
-(void)ButtonClicked:(UIButton *)sender{
VersusSelectionView *versusSelectionView=[[VersusSelectionView alloc]initWithNibName:@"VersusSelectionView" bundle:nil];
versusSelectionView.selectedChapter=[sender.titleLabel.text intValue];
appDelegate.selectedChapterIndex=[sender.titleLabel.text intValue];
self.hidesBottomBarWhenPushed=YES;
versusSelectionView.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
[self presentModalViewController:versusSelectionView animated:YES];
[UIView commitAnimations];
[versusSelectionView release];
}
上面的代码对我来说工作正常,问题在于以下返回代码:
返回书籍选择代码(不起作用) -
-(IBAction)_clcikbtnchptselction:(id)sender
{
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:[[BookSelectionview alloc] initWithNibName:@"BookSelectionview" bundle:nil]];
[self presentModalViewController:navigationController animated:YES];
[navigationController release];
}
这是从诗句选择页面返回章节选择页面的代码(不起作用) -
-(IBAction)_clcikbtncloseversselctn:(id)sender
{
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:[[chapterSelectionview alloc] initWithNibName:@"chapterSelectionview" bundle:nil]];
[self presentModalViewController:navigationController animated:YES];
[navigationController release];
}
什么我的错误在这里代码,请帮我解决这个问题。 谢谢。
Ha ii everybody,i met with a problem in one of my view-controllers in my app.
i am developing a bible app which contains book selection page then chapter selection then verse selection,the architecture is that when the user click any of the book button in bookviewcontroller it will navigate to chapterselection page of corresponding book, then the user select one of the chapter button it redirect to coresponding chapter verse page.
every thing works fine for me,but my problem is there is no back navigation action occur in these pages. there is backbutton in chapter selection and verse selection page but the navigation back didnot work,i tried lott to solve this bug but no use,my code for navigation is:
this is chapter selection redirecting code in book selection -
-(void)ButtonClicked:(UIButton *)sender{
ChapterSelectionView *chapterSelectionView=[[ChapterSelectionView alloc]initWithNibName:@"ChapterSelectionView" bundle:nil];
chapterSelectionView.selectedIndex=sender.tag;
appDelegate.selectedBookIndex=sender.tag;
self.hidesBottomBarWhenPushed=YES;
chapterSelectionView.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
[self presentModalViewController:chapterSelectionView animated:YES];
[UIView commitAnimations];
[chapterSelectionView release];
}
this is redirction to verse page code -
-(void)ButtonClicked:(UIButton *)sender{
VersusSelectionView *versusSelectionView=[[VersusSelectionView alloc]initWithNibName:@"VersusSelectionView" bundle:nil];
versusSelectionView.selectedChapter=[sender.titleLabel.text intValue];
appDelegate.selectedChapterIndex=[sender.titleLabel.text intValue];
self.hidesBottomBarWhenPushed=YES;
versusSelectionView.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
[self presentModalViewController:versusSelectionView animated:YES];
[UIView commitAnimations];
[versusSelectionView release];
}
the above code works fine for me, the problem is with the following code for going back:
back to bookselection code (not working) -
-(IBAction)_clcikbtnchptselction:(id)sender
{
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:[[BookSelectionview alloc] initWithNibName:@"BookSelectionview" bundle:nil]];
[self presentModalViewController:navigationController animated:YES];
[navigationController release];
}
this is the code for back to chapter selection page from verse selection page(not working) -
-(IBAction)_clcikbtncloseversselctn:(id)sender
{
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:[[chapterSelectionview alloc] initWithNibName:@"chapterSelectionview" bundle:nil]];
[self presentModalViewController:navigationController animated:YES];
[navigationController release];
}
Whats the bug here in my code,please help me to solve this.
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不是专家,但我在你的代码中看到的是你每次都创建一个新的 UINavigationController 对象所以你的导航控制器在堆栈中只有一个对象,那么返回将如何工作?
要使用导航控制器,您必须将chapterview推送到UINavigationController,然后您可以使用后退按钮弹出推送的视图......
您的流程应该像这样
导航控制器 - initWith 1. BookSelectionview
推至 2.ChapterSelectionview
推至3.所选章节
I am not an expert, but what I can see in your code is you are making a new object of UINavigationController every time So your navigation controller is having only one object in the stack, so how back will work?
To use navigation controller you must have pushed chapterview, to the UINavigationController and then you can use back button to pop the pushed view....
Your flow should be like this
Navigation controller- initWith 1. BookSelectionview
push to 2. ChapterSelectionview
push to 3. Selected chapter