Dismissal Issues in UIPopOverViewControler - iphone

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.......

Related

Navigation issue in Iphone SDK

I have a view(HomeView) in which i open a popOver. The popoVer content View is (ListView) which contains a Table View.
Now, when i select the row, The HomeView will dismissed & open a new View(MapView).
Till now, It works fine. But my all views contain tabbar in xib. I don't have tab bar in ListView.
So, i just open MapView with present Modal View. But from that my navigation is not working.
My code is as following.
HomeView.m
//open popview with ListView
-(IBAction)btnTableMenu_TouchUpInside:(id)sender{
ListView *popUp=[[ListView alloc] initWithNibName:#"ListView" bundle:nil];
popView = [[UIPopoverController alloc]initWithContentViewController:popUp];
popView.delegate =self;
[popView setPopoverContentSize:CGSizeMake(300, 700)];
[popView presentPopoverFromRect:CGRectMake(150,25,20,50) inView:self.view permittedArrowDirections:UIPopoverArrowDirectionUp animated:YES];
}
ListView.m
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
[[NSNotificationCenter defaultCenter] postNotificationName:#"DismissModal"object:self];
MapViewController *mapVC=[[MapViewController alloc]initWithNibName:#"MapViewController_ipad" bundle:nil];
[self presentModalViewController:mapVC animated:YES];
//[self.navigationController pushViewController:mapVC animated:YES];
}
How can i solve this??
you just do like this way:-
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
[[NSNotificationCenter defaultCenter] postNotificationName:#"DismissModal"object:self];
MapViewController *mapVC=[[MapViewController alloc]initWithNibName:#"MapViewController_ipad" bundle:nil];
UINavigationController *navbar = [[UINavigationController alloc] initWithRootViewController:mapVC];
navbar.navigationBar.tintColor =[UIColor colorWithRed:255/255.0 green:108/255.0 blue:61/255.0 alpha:0.1];
[navbar setModalPresentationStyle:UIModalPresentationFormSheet];
[navbar setModalTransitionStyle:UIModalTransitionStyleFlipHorizontal];
[self presentModalViewController:navbar animated:YES];
}
in MapViewController.m file ViewDidLoad
- (void)viewDidLoad
{
[super viewDidLoad];
UIBarButtonItem *CancleButton = [[UIBarButtonItem alloc] initWithTitle:#"Cancel" style:UIBarButtonItemStyleBordered target:self action:#selector(cancel)];
self.navigationItem.leftBarButtonItem = CancleButton;
}
-(void)cancel
{
[self dismissModalViewControllerAnimated:YES];
}
Do you know the difference btw ..
[self presentModalViewController:controller animated:YES];
& [self.navigationController pushViewController:controller animated:YES];
\When you do presentModalViewController:controller you lost the last Navigation stack.You need to create different navigationController for presenting the View. Read this properly you will get Idea .
http://developer.apple.com/library/ios/#featuredarticles/ViewControllerPGforiPhoneOS/Introduction/Introduction.html
Try following these-
ListView.m
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
[[NSNotificationCenter defaultCenter] postNotificationName:#"DismissModal"object:self userInfo:[NSDictionary dictionaryWithObject:#"map" forKey:#"selectedView"]];
}
HomeView.m
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(dismissModal:) name:#"DismissModal" object:nil];
- (void) dismissModal:(NSNotification *)notification
{
[self dismissModalViewController:mapVC animated:NO];
if([[notification.userInfo valueForKey:#"selectedView"] isEqualToString:#"map"])
{
MapViewController *mapVC=[[MapViewController alloc]initWithNibName:#"MapViewController_ipad" bundle:nil];
UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:mapVC];
[self presentModalViewController:navController animated:YES];
}
}

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 to dismiss a Form sheet model view in 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];
}

Transition of popover controller in ipad

when i click this button thee comes a popover for search the text in the view..but when i type god ,so the sentence with go comes inside the popover controller tableviewcell,when i click the cell,the search result show in the popover itself,it is not redirecting to the mainvieww.my code or popover controller is
- (void)Searchpage:(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.popoverController = [[UIPopoverController alloc]
initWithContentViewController:navigationController];
//present the popover view non-modal with a
//refrence to the button pressed within the current view
[self.popoverController presentPopoverFromRect:CGRectMake(600, 0, 0, 0)
inView:self.view
permittedArrowDirections:UIPopoverArrowDirectionAny
animated:YES];
//release the popover content
[popoverContent release];
}
in the search page popover controller ,i put this code to redirect to main view
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
// Navigation logic may go here. Create and push another view controller.
ParallelReadViewController *detailViewController = [[ParallelReadViewController alloc] initWithNibName:#"ParallelReadViewController" bundle:nil];
[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];
}
parallelViewController is the Main view,but now i get the Mainview inside the popover controller.i just want to dismiss this popover controller and navigate to parallelviewcontroller.how to do this.
Thanks in advance.
You can use
- (void)dismissPopoverAnimated:(BOOL)animated
method to dismiss popover.
And can refer following link for more info - http://developer.apple.com/library/ios/#documentation/UIKit/Reference/UIPopoverController_class/Reference/Reference.html
EDIT -
You can get your class that contains popover by using -
NSArray *viewControllerArray = [[self.navigationController.viewControllers copy] autorelease];
int arrayElementCount = [viewControllerArray count];
YourViewController *aViewController;
for(int index = 0 ; index < arrayElementCount ; index++) {
if([[viewControllerArray objectAtIndex:index] isKindOfClass:[YourViewController class]]) {
aViewController = [viewControllerArray objectAtIndex:index];
}
}
[aViewController.popoverController dismissPopoverAnimated:YES];

returning null inside tableview delegate

HI
I am working on UITablview based project. i like to load a new view when ever a cell got click. i am using following code in didselectRowAtIndexPath delegate method.
The below coding is not showing any error but new view not get load and [self navigationController] is returning null.
inside Viewdidload function [self navigationcontroller] returning proper value. but inside Delegate method [self navigationcontroller] returns null.
/// inside appDelegate class
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
self.viewController = [[LAMainViewController_iPhone alloc]initWithNibName:#"LAMainViewController_iPhone" bundle:nil];
UINavigationController *controller = [[UINavigationController alloc]initWithRootViewController:viewController];
[window addSubview:controller.view];
[controller release];
[window makeKeyAndVisible];
return YES;
}
/// inside LAmainviewcontroller.m
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
if ((self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil])) {
// Custom initialization
}
//self.navigationController.navigationBar.backgroundColor =[UIColor clearColor];// .title=#"test";
return self;
}
- (void)viewDidLoad {
[super viewDidLoad];
NSString *materialPlistPath = [[NSBundle mainBundle]pathForResource:#"materials" ofType:#"plist"];
materialList = [[NSArray alloc]initWithContentsOfFile:materialPlistPath];
materialTable.backgroundColor = [UIColor blackColor];
NSLog(#" dud kiad navigationController %#", self.navigationController);
//2010-10-20 15:22:03.809 LabAssistant[17368:207] dud kiad navigationController <UINavigationController: 0x5f3b160>
}
-(void)viewWillAppear:(BOOL)animated{
[super viewWillAppear:YES];
self.navigationController.navigationBarHidden = YES;
NSIndexPath *indexPath = [materialTable indexPathForSelectedRow];
[materialTable deselectRowAtIndexPath:indexPath animated:YES];
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
LAMaterialPropertiesViewController_iPhone *materialPropertyListView = [[[LAMaterialPropertiesViewController_iPhone alloc] initWithNibName:#"LAMaterialPropertiesViewController_iPhone" bundle:nil] autorelease];
materialPropertyListView.chemicalName = [[materialList objectAtIndex:[indexPath row]] objectForKey:#"materialProperty"];
[[self navigationController] pushViewController:materialPropertyListView animated:YES];
NSLog(#"%#",[self navigationController]);
///2010-10-20 16:20:42.634 LabAssistant[17656:207] navigationController (null)
}
please help me to fix this issue.
thanks!
Remove the autorelease from the init statement. Actually the viewcontroller is getting released before it gets pushed.
instead of
LAMaterialPropertiesViewController_iPhone *materialPropertyListView = [[[LAMaterialPropertiesViewController_iPhone alloc] initWithNibName:#"LAMaterialPropertiesViewController_iPhone" bundle:nil] autorelease];
try this
LAMaterialPropertiesViewController_iPhone *materialPropertyListView = [[LAMaterialPropertiesViewController_iPhone alloc] initWithNibName:#"LAMaterialPropertiesViewController_iPhone" bundle:nil];
Hope this will solve your problem.
I think the table view delegate is called before the navigation controller is set to the view controller.
Can you try reloading the tableview [tableview reloadData]; in viewWillAppear or viewDidAppear?