how to dismiss a Form sheet model view in iPhone

2019-08-22 07:06发布

I have three pages. Each page pushes some values to next page like this: bookpage----------values passing to >chapterpage----------values passing to>verse page. When the user taps the button from the main page it shows a model form sheet which has book page. The code for this is:

    BookSelectionview *detailViewController = [[BookSelectionview alloc] initWithNibName:@"BookSelectionview" bundle:nil];

    UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:detailViewController];
    navController.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
    navController.modalPresentationStyle = UIModalPresentationFormSheet;

    UIBarButtonItem *doneBarButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone
                                                                                   target:self
                                                                                   action:@selector(modalViewDone)];
    detailViewController.navigationItem.rightBarButtonItem = doneBarButton;
    detailViewController.navigationItem.title = @"Book Selection";
    [doneBarButton release];

    [self.navigationController presentModalViewController:navController animated:YES];
    [detailViewController release];
    [navController release];
    [self resetReadViewToVerse:1];
}

Then in my chapter page I wrote this code to navigate and pass some value to verse page.

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{         
    ChapterSelectionView *detailViewController = [[ChapterSelectionView alloc] initWithNibName:@"ChapterSelectionView" bundle:nil];
    detailViewController.contentSizeForViewInPopover = CGSizeMake(500, 600);

    //detailViewController.firstString = firstString;
    // ...
    // Pass the selected object to the new view controller.
    detailViewController.selectedIndex=indexPath.row;
    appDelegate.selectedBookIndex=indexPath.row;
    self.hidesBottomBarWhenPushed=YES;
    [self.navigationController pushViewController:detailViewController animated:YES];

    [detailViewController release];         
}

and in verse page here is the problem....in tho page includes bible verse which is in the form of buttons when the use tap any button it need to go to the main view and show the corresponding verse,,but it shows the main page inside the form sheet,with the correspondent verse..so i put the dismissmodelview animated:yes to the code.but it cashes..my code in verse page its in button click

appDelegate.selectedBook = [appDelegate.books objectAtIndex:appDelegate.selectedBookIndex];
appDelegate.selectedChapter = [NSString stringWithFormat:@"%d",appDelegate.selectedChapterIndex];
appDelegate.selectedVerse = [NSString stringWithFormat:@"%d",[sender.titleLabel.text intValue]];
[appDelegate reloadVerses];

ParallelReadViewController *detailViewController = [[ParallelReadViewController alloc] initWithNibName:@"ParallelReadViewController" bundle:nil];

[self.navigationController pushViewController:detailViewController animated:YES];

[detailViewController release];
[self.navigationController dismissModalViewControllerAnimated:YES];

How can I dismiss the form sheet and go to main page(parallelreadviewcontroller) with the corresponding verse?

1条回答
beautiful°
2楼-- · 2019-08-22 08:07

Add a notification in main view's viewDidLoad

[[NSNotificationCenter defaultCenter] addObserver:self 
                                         selector:@selector(dismissTheModelView:) 
                                             name:@"dismissTheModelView" 
                                           object:nil];

write function in Main view

-(void)dismissTheModelView:(id)sender
{
     [self dismissModalViewControllerAnimated:YES];
}

and finally post the notification from where u have to dismiss the popover controller, like

-(IBAction)cancelButtonPressed:(id)sender
{
    [[NSNotificationCenter defaultCenter] postNotificationName:@"dismissTheModelView" object:nil];
}
查看更多
登录 后发表回答