ICoder
ICoder

Reputation: 1347

Navigation error in iphone sdk

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.

Upvotes: 0

Views: 112

Answers (1)

Minakshi
Minakshi

Reputation: 1433

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

Upvotes: 1

Related Questions