Transition of popover controller in ipad - iphone

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

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.

ipad popOverController navigation Doubts

I am displaying a view controller as a popover on button click, and it seems to work fine.However selecting a tableview cell does not navigate to next page.
My first button click code is
-(IBAction)_clickbtnChapterselection:(id)sender
{
//build our custom popover view
BookSelectionview* popoverContent = [[BookSelectionview alloc]
init];
//resize the popover view shown
//in the current view to the view's size
popoverContent.contentSizeForViewInPopover =
CGSizeMake(500, 600);
//create a popover controller
self.popoverController = [[UIPopoverController alloc]
initWithContentViewController:popoverContent];
//present the popover view non-modal with a
//refrence to the button pressed within the current view
[self.popoverController presentPopoverFromRect:_btnChapterSelection.frame
inView:self.view
permittedArrowDirections:UIPopoverArrowDirectionAny
animated:YES];
//release the popover content
[popoverContent release];
[self resetReadViewToVerse:1];
}
in the didselectrowat index path clcik of BookSelectionview
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
ChapterSelectionView *detailViewController = [[ChapterSelectionView alloc] initWithNibName:#"ChapterSelectionView" bundle:nil];
detailViewController.selectedIndex=indexPath.row;
appDelegate.selectedBookIndex=indexPath.row;
self.hidesBottomBarWhenPushed=YES;
[self.navigationController pushViewController:detailViewController animated:YES];
[detailViewController release];
How do I make cell select navigate to Chapterselectionview?
please help me.
Thanks in advance.
You don't have UINavigationController into your pop-up, so it works normal. Change it to support navigation like this:
//build our custom popover view
BookSelectionview* popoverContent = [[BookSelectionview 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(500, 600);
//create a popover controller
self.popoverController = [[UIPopoverController alloc]
initWithContentViewController:navigationController];

pushViewController issue

I've got a TabBar application and 2 views.
One view is a MKMapView with annotations and callouts etc. All works well. Clicking on the 'UIButtonTypeDetailDisclosure' button in the callout my 'showDetails' function fires (NSLOG..).
Now I want to push a DetailView in 'showDetails'. I'd have to either use pushViewController or presentModalViewController
#pragma mark - MKMap methods
- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>) annotation{
if([annotation isKindOfClass:[CustomPlacemark class]])
{
MKPinAnnotationView *newAnnotation = [[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:[annotation title]];
newAnnotation.pinColor = MKPinAnnotationColorGreen;
newAnnotation.animatesDrop = YES;
newAnnotation.canShowCallout = YES;
newAnnotation.enabled = YES;
//newAnnotation.pinColor=MKPinAnnotationColorPurple;
NSLog(#"Created annotation at: %f %f", ((CustomPlacemark*)annotation).coordinate.latitude, ((CustomPlacemark*)annotation).coordinate.longitude);
[newAnnotation addObserver:self
forKeyPath:#"selected"
options:NSKeyValueObservingOptionNew
context:#"GMAP_ANNOTATION_SELECTED"];
UIImageView *leftIconView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"leftIconView.png"]];
newAnnotation.leftCalloutAccessoryView = leftIconView;
[leftIconView release];
UIButton* rightButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
[rightButton setTitle:annotation.title forState:UIControlStateNormal];
[rightButton addTarget:self
action:#selector(showDetails:)
forControlEvents:UIControlEventTouchUpInside];
newAnnotation.rightCalloutAccessoryView = rightButton;
[newAnnotation autorelease];
return newAnnotation;
}
return nil;
}
- (void) showDetails:(id)sender {
NSLog(#"Annotation Click");
[self.navigationController pushViewController:self.detailViewController animated:YES];
// I want to push a new View here...
}
Unfortunately this doesn't do anything (No error / no action). I reckon it's because I don't have a navigationController to use pushViewController.
- (void) showDetails:(id)sender {
NSLog(#"Annotation Click");
[self.navigationController pushViewController:self.detailViewController animated:YES];
// I want to push a new View here...
}
i am trying to create and push a DetailViewController in the navigationController when my 'UIButtonTypeDetailDisclosure' button in notification is clicked. but navigationController is nil
Any idea what to add to my 'showDetails' function?
Much appreciated
You need to have a navigation controller before pushing views on it:
DetailViewController *detailController = [[DetailViewController alloc] initWithNibName:#"DetailViewController" bundle:[NSBundle mainBundle]];
// this line calls the viewDidLoad method of detailController
detailController.view.hidden = NO;
UINavigationController *navigationController = [[UINavigationController alloc] detailController];
navigationController.navigationBarHidden = YES;
[navigationController setView:detailController.view];
[self.view addSubview:navigationController.view];
[detailController release];
[navigationController release];
Be careful this will initialize navigationController again and again if you do this in your showDetails:. So you need to initialize your navigation controller in eg. viewDidLoad and then you will be able to push your detailController onto it
If you want to push a view controller with a navigation controller, then your initial view must be within the navigation controller to begin with.
In your case, your tab bar controller should probably be put in the navigation controller if it isn't already. Then you can call your showDetails method the way you have done above. If it is in the nav controller, maybe you can post the code where you do that and I can try and offer more assistance.
Here is how you might do something like this in your applicationDidFinishLaunchingWithOptions: method
FirstViewController *fvc = [[FirstViewController alloc] init];
SecondViewController *svc = [[SecondViewController alloc] init];
UITabBarController *tabcon = [[UITabBarController alloc] init];
tabcon.viewControllers = [NSArray arrayWithObjects:fvc,svc,nil];
UINavigationController *navcon = [[UINavigationController alloc] initWithRootViewController:tabcon];
[self.window addSubview:navcon.view];
Then when you want to push a detail view controller, you just call:
DetailViewController *dvc = [[DetailViewController alloc] init];
[self.navigationController pushViewController:dvc];
If you set your view controllers as properties, you can call self.viewControllerName, just make sure you are allocating memory for them as well. Embedding your tab bar controller in a navigation controller like this gives you all the window dressing (back buttons, title bar, etc.) for free and it will adapt to your different views as they come on screen.

problem in UITable cell selection

hai ,
i have coded in UITableview in the method as follows.but when i touch the cell or row ,it wont
go to the next page(navigation did not work).have i to declare navigation conroller in other file.but i have coded app delegate in applicationdidfinishmethod for tab bar through dynamic.how can i link navigation?
the code:
UITableview;(TableViewController)
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
SubController *nextController = [[SubController alloc] init];
[self.navigationController pushViewController:nextController animated:YES];
[nextController release];
}
appdelegation:
- (void)applicationDidFinishLaunching:(UIApplication *)application {
tabBarController = [[UITabBarController alloc] init];
tabBarController.navigationItem.title = #" News";
TableViewController *rtbfViewController = [[TableViewController alloc]
init];
rtbfViewController.tabBarItem.title = #"News";
InfoViewController *infoViewController = [[InfoViewController alloc]
initWithStyle:UITableViewStyleGrouped];
infoViewController.tabBarItem.title = #"Info";
tabBarController.viewControllers = [NSArray
arrayWithObjects:rtbfViewController,infoViewController,nil];
tabBarController.customizableViewControllers = [NSArray arrayWithObjects:nil];
[window addSubview:tabBarController.view];
[window makeKeyAndVisible];
}
The problem is, that you don't have a UINavigationController, so self.navigationController in your TableViewController is nil (and thus messages sent to this property are ignored). You should modify your code in the app delegate as follows:
// [...] create tab bar view controller...
// create navigation controller with TableViewController instance as root view controller
TableViewController *rtbfViewController = [[TableViewController alloc] init];
rtbfViewController.tabBarItem.title = #"News";
UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:rtbfViewController];
// [...] create other view controllers
// NOTE: add the navigation controller to the tab bar controller, rather than the TableViewController
tabBarController.viewControllers = [NSArray arrayWithObjects:navController,infoViewController,nil];
tabBarController.customizableViewControllers = [NSArray arrayWithObjects:nil];
And don't forget to release your view controllers afterwards:
[rtbfViewController release];
[navController release];
[infoViewController release];