how to dismiss a Form sheet model view in iPhone - iphone

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?

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];
}

Related

Dismissal Issues in UIPopOverViewControler

I am having a popovercontroller to dispay a search page ,it shows the search page nicly,when the user tap the cell inside the popover it will show the corresponding page inside the popovercontroller,I dont want it,so I put the NSNotification for displaying the popover,and it works fine,but I got a problem that ,but navigation is not happen there in popovercontroller ,only dismissal happen.
this is my code to create a popover
-(void)revealRightSidebar:(id)sender
{
searchpage* popoverContent = [[searchpage alloc]
init];
UINavigationController *navigationController = [[[UINavigationController alloc] initWithRootViewController:popoverContent] autorelease];
//resize the popover view shown
//in the current view to the view's size
popoverContent.contentSizeForViewInPopover =
CGSizeMake(320,650);
//create a popover controller
self.popup = [[UIPopoverController alloc]
initWithContentViewController:navigationController];
[self.popup presentPopoverFromRect:_btnsearch.frame
inView:self.view
permittedArrowDirections:UIPopoverArrowDirectionAny
animated:YES];
//release the popover content
[popoverContent release];
[self resetReadViewToVerse:1];
}
in viewDidLoad method of this page i put the notification
- (void)viewDidLoad
{
[super viewDidLoad];
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(dismissThePopover) name:#"popoverShouldDismiss" object:nil];
}
in searchpage i put this code to navigate to the corresponding search result page
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
ParallelReadViewController *detailViewController = [[ParallelReadViewController alloc] initWithNibName:#"ParallelReadViewController" bundle:nil];
//detailViewController.firstString = firstString;
// ...
// Pass the selected object to the new view controller.
[self.navigationController pushViewController:detailViewController animated:YES];
[detailViewController release];
delegate.selectedBook = [[searchResults objectAtIndex:indexPath.row] objectForKey:#"book"];
delegate.selectedChapter = [[searchResults objectAtIndex:indexPath.row] objectForKey:#"chapter"];
delegate.selectedVerse = [[searchResults objectAtIndex:indexPath.row] objectForKey:#"verse"];
[delegate reloadVerses];
[[NSNotificationCenter defaultCenter] postNotificationName:#"popoverShouldDismiss" object:nil];
}
but when I remove the notification it navigate to the correspondent search in parallelReadViewController page ,but within the popover itself,here the popover dismiss,but no navigation.please help me to do this.
You must be having a navigationController declared inside the AppDelegate class. Use that navigationController for pushing the required view.
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
ParallelReadViewController *detailViewController = [[ParallelReadViewController alloc] initWithNibName:#"ParallelReadViewController" bundle:nil];
//detailViewController.firstString = firstString;
// ...
// Pass the selected object to the new view controller.
[delegate.navigationController pushViewController:detailViewController animated:YES];
[detailViewController release];
delegate.selectedBook = [[searchResults objectAtIndex:indexPath.row] objectForKey:#"book"];
delegate.selectedChapter = [[searchResults objectAtIndex:indexPath.row] objectForKey:#"chapter"];
delegate.selectedVerse = [[searchResults objectAtIndex:indexPath.row] objectForKey:#"verse"];
[delegate reloadVerses];
[[NSNotificationCenter defaultCenter] postNotificationName:#"popoverShouldDismiss" object:nil];
}
Hope this might help you.......

how to dismiss a popovercontroler from anotherviewcontroler

i have a barbutton in the main menu..tapping that button will show a popoveontroller,,,called bookselectionview,,,it consists of tableview ,,when i tap the cel it navigate to the another view controller inside the popover,,seondview consists of buttons,,when i tap any button it navigate to third view controller inside the popover controller...all works fineee..but my problem is,,i want to dismiss this popoverontroller when i tap any button in the thirdview...and must navigate to main view ..now it shows the main view inside the popoverontrollerr..i had tried many things,,but nothing helps me...my code for this is...
in my bar button of the main view i put this code
BookSelectionview* popoverContent = [[BookSelectionview alloc]
init];
UINavigationController *navigationController = [[[UINavigationController alloc] initWithRootViewController:popoverContent] autorelease];
popoverContent.contentSizeForViewInPopover =
CGSizeMake(500, 800);
self.popup = [[UIPopoverController alloc]
initWithContentViewController:navigationController];
[self.popup presentPopoverFromRect:CGRectMake(348, 0, 0, 0)
inView:self.view
permittedArrowDirections:UIPopoverArrowDirectionAny
animated:YES];
then in my bookselectionview controller i put this ode in my tableview did select metho
- (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];
}
in my seconview(chapterselectionview) i put this codee in the button cilk
-(void)ButtonClicked:(UIButton *)sender{
[NSThread detachNewThreadSelector: #selector(spinBeginchapterselection) toTarget:self withObject:nil];
VersusSelectionView *detailViewController = [[VersusSelectionView alloc] initWithNibName:#"VersusSelectionView" bundle:nil];
detailViewController.contentSizeForViewInPopover =
CGSizeMake(500,600);
detailViewController.selectedChapter=[sender.titleLabel.text intValue];
appDelegate.selectedChapterIndex=[sender.titleLabel.text intValue];
self.hidesBottomBarWhenPushed=YES;
[self.navigationController pushViewController:detailViewController animated:YES];
[detailViweController relese];
then in my third view that is verseviewcontroller i put this code to navigate to main view(parallelReaviewcontroller)here i need to dismiss the popup....
-(void)ButtonClicked:(UIButton *)sender{
[self dismissModalViewControllerAnimated:YES];
[NSThread detachNewThreadSelector: #selector(spinBeginverseselection) toTarget:self withObject:nil];
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];
please help me to solve this problem,,,thanks in advance.

How can I push a new viewController into an existing view within another view controller?

Is it possible to push a new viewController into an existing view within another view controller?
Here is my setup to begin with:
You can see that I have a UITableView. When a cell is tapped, a new view controller is pushed using this code;
DetailTableViewController *viewcontroller = [[DetailTableViewController alloc] initWithStyle:UITableViewStyleGrouped];
viewcontroller.item = (MWFeedItem *)[itemsToDisplay objectAtIndex:indexPath.row];
[self presentViewController:viewcontroller animated:YES completion:nil];
[viewcontroller release];
Unfortunately this looks like this though and sits on top of the bar at the top saying "Will Roberts"
Why is this happening as it's clearly outside of the view I set it to be pushed from...
Instead of "presentViewController", use
DetailTableViewController *viewcontroller = [[DetailTableViewController alloc] initWithStyle:UITableViewStyleGrouped];
viewcontroller.item = (MWFeedItem *)[itemsToDisplay objectAtIndex:indexPath.row];
[self.navigationController pushViewController:viewcontroller animated:YES];
[viewcontroller release];
or use modal view controller
[self presentModalViewController:viewcontroller animated:YES]
//Presenting new view controller with navigation controller will help you.
DetailTableViewController *viewcontroller = [[DetailTableViewController alloc] initWithStyle:UITableViewStyleGrouped];
viewcontroller.item = (MWFeedItem *)[itemsToDisplay objectAtIndex:indexPath.row];
[self.navigationController presentViewController:viewcontroller animated:YES completion:nil];
[viewcontroller release];
//Edited
DetailTableViewController *viewcontroller = [[DetailTableViewController alloc] initWithStyle:UITableViewStyleGrouped];
UINavigationController *nav1=[[UINavigationController alloc]initWithRootViewController:viewController1];
[self presentModalViewController:nav1 animated:YES];

Why is presentModalViewController not working?

I am presenting a modalcontroller in a view, after i dissmiss the view i want to present another modalView but the code is not working, i have a delegate method that is being called when i press a button on the first modal vieview in witch i have the code.
inside the parentView the method for the firstview delegat:
-(void)newMessageModalView:(NewMessageModalView *)controller didFinishSelecting:(int)selectedChannel{
[self dismissModalViewControllerAnimated:YES];
SecondView * detailView = [[SecondView alloc] initWithNibName:#"SecondView" bundle:nil];
[self presentModalViewController:SecondView animated:YES];
[detailView release];
[self dismissModalViewControllerAnimated:YES];
}
You are presenting SecondView, which is your class and not your instance. Even if that was right, you are dismissing it straight away.
Move [self dismissModalViewControllerAnimated:YES]; to detailView.m
-(void)newMessageModalView:(NewMessageModalView *)controller didFinishSelecting:(int)selectedChannel{
SecondView * detailView = [[SecondView alloc] initWithNibName:#"SecondView" bundle:nil];
[self presentModalViewController:SecondView animated:YES];
[detailView release];
}
For example, in detailView.m
- (void)cancelBtnTouched:(id)sender {
[self dismissModalViewControllerAnimated:YES];
}

Why is my popToRootViewControllerAnimated not getting called?

I have even tried implementing a delay right before the call to popToRootViewControllerAnimated however that does no good either. It just does not get called.
-(IBAction) btnSignOut{
[[self tabBarController]setSelectedIndex:0];
[[self navigationController]popToRootViewControllerAnimated:NO];//DOES NOT GET CALLED
Overview *overviewController = [[Overview alloc] initWithNibName:#"Overview" bundle:nil];
//Lets place OverView in navController
UINavigationController * navController = [[UINavigationController alloc] initWithRootViewController:overviewController];
// [[self navigationController] popToViewController:ComposeViewController animated:YES];
//Now lets display it
[self.tabBarController presentModalViewController:navController animated:YES];
[navController release];
[overviewController release];
}
It seems like the [self navigationController] does not contain any view to pop