How can i use popover controller in UIPageViewController? - iphone

Can i use the popover controller to get back to previous view controllers in page view controller. Is there any method to do so.
This code i am trying.
-(void)goNext
{
Vcontr = [self.pageController.viewControllers objectAtIndex:0];
UIPopoverController *popoverController = [[UIPopoverController alloc] initWithContentViewController:pageController];
if(popoverController == nil){ //make sure popover isn't displayed more than once in the view
popoverController = [[UIPopoverController alloc] initWithContentViewController:pageController];
}
[popoverController presentPopoverFromRect:self.view.frame inView:self.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
popoverController.delegate = self;
}

Here are some tutorials:
iPad for iPhone Developers 101: UIPopoverController Tutorial
iPad UIPopoverController Video
and read Apple developers
and you can find sample code by Apple developers

UIPopoverController *popoverController ;///defin this in the .h
if(popoverController == nil){ //make sure popover isn't displayed more than once in the view
popoverController = [[UIPopoverController alloc] initWithContentViewController:yourPageViewController];
}
[popoverController presentPopoverFromRect:self.view.frame inView:self.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
popoverController.delegate = self;
}

Related

Make Popover Background Black in Interface Builder

I've successfully hooked up several popover views in interface builder. I've tried to make the background black by setting the view background color to black, but I am still getting a white arrow on the popover itself and white artifacts on the 4 rounded corners.
Please see the screenshot.
What can I do to make the background totally black in interface builder?
I appreciate the answer below but I still can't quite get it to work - here is my code:
// Show the satellite Ephemeris
if ( itemIndex == 1 ) {
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
NSLog(#"This is an iPad - Creating popover!");
EphemerisDataView *ephemView = [[EphemerisDataView alloc] init];
UIPopoverController *popOver = [[UIPopoverController alloc] initWithContentViewController:ephemView];
[popOver setPopoverBackgroundViewClass:[DDPopoverBackgroundView class]];
[popOver.popoverBackgroundViewClass setTintColor:[UIColor blackColor]];
CGSize size = CGSizeMake(320, 480); // size of view
popOver.popoverContentSize = size;
[popOver presentPopoverFromRect:self.popOverAnchor.bounds inView:self.view
permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
}
else {
NSLog(#"This is not an iPad - Performing segue...");
// Show the next view
[self performSegueWithIdentifier:#"Ephemeris" sender:self];
}
}
You cannot customize that arrow by IB. You will need a totally customized popover for you. Plenty of them are available on git. But If you want to use default one then it is not possible to customize that arrow as well.
Do it like this:
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
NSLog(#"This is an iPad - Creating popover!");
UIStoryboard *storyboard = [UIStoryboard storyboardWithName: #"MainStoryboard_iPad" bundle:[NSBundle mainBundle]];
EphemerisDataView *ephemView = [storyboard instantiateViewControllerWithIdentifier:#"EphemerisDataView"];
UIPopoverController *popOver = [[UIPopoverController alloc] initWithContentViewController:ephemView];
self.customPopoverController = popOver;
[popOver setPopoverBackgroundViewClass:[DDPopoverBackgroundView class]];
[popOver.popoverBackgroundViewClass setTintColor:[UIColor blackColor]];
popOver.delegate = self;
CGSize size = CGSizeMake(320, 480); // size of view
popOver.popoverContentSize = size;
[popOver presentPopoverFromRect:self.popOverAnchor.bounds inView:self.popOverAnchor
permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
}
else {
NSLog(#"This is not an iPad - Performing segue...");
// Show the next view
[self performSegueWithIdentifier:#"Ephemeris" sender:self];
}

UIPopoverController disappears when ipad orientation changes

Popover appears properly when I click on button.
When orientation changes then it disappears & leave a black topbar.
Below is the reference image.
Can anyone suggest, why it is happening?
My Code:
EBFirstViewController *firstViewController = [[EBFirstViewController alloc]init];
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:firstViewController];
navigationController.delegate = self;
UIPopoverController *popover = [[UIPopoverController alloc] initWithContentViewController:navigationController];
self.popoverController = popover;
popoverController.delegate = self;
[popoverController setPopoverContentSize:CGSizeMake(320.0f, 527.0f)];
[popoverController presentPopoverFromRect:settingsBtn.frame inView:self.view permittedArrowDirections:UIPopoverArrowDirectionUp animated:YES];
For That following code help to solve your problem.
- (void)application:(UIApplication *)application willChangeStatusBarOrientation:(UIInterfaceOrientation)newStatusBarOrientation duration:(NSTimeInterval)duration {
// a cheat, so that we can dismiss all our popovers, if they're open.
if (ObjPopover) {
// if we're actually showing the menu, and not the about box, close out any active menu dialogs too
if (menuPopoverVC && menuPopoverVC == ObjPopover.contentViewController)
[menuPopoverVC.popoverController dismissPopoverAnimated:YES];
[menuPopoverPC dismissPopoverAnimated:YES];
menuPopoverPC = nil;
}
}
- (void)popoverControllerDidDismissPopover:(UIPopoverController *)popoverController {
// the user (not us) has dismissed the popover, let's cleanup.
ObjPopover = nil;
}

how to show the UIPopoverController when button clicked in iPhone

I have a problem with UIPopoverController. On button press I need to display the UIPopoverController. This is the code.
-(IBAction)hintButton:(id)sender{
CGRect contentRect = CGRectMake(0, 0, 200, 40);
UIViewController* popoverContent = [[UIViewController alloc] init];
popoverContent.view = hintB;
popoverContent.contentSizeForViewInPopover = contentRect.size;
if(popoverController == nil){ //make sure popover isn't displayed more than once in the view
popoverController = [[UIPopoverController alloc]initWithContentViewController:popoverContent];
[popoverController presentPopoverFromBarButtonItem:sender permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
popoverController.delegate = self;
}
}
When I press the button application crashes.
UIPopoverController cannot be used for iPhone applications. It's only for iPad apps.
However, you can have this functionality by creating custom UIPopoverController. You can find a custom UIPopoverController sample here.
Let me know if you have any similar questions.
Thanks,
MinuMaster

How can I use UIModalPresentationFormSheet with NavigationController in iPad?

I want to use UIModalPresentationFormSheet in my app. But i'm using navigation controller. So when i writes following code it is not responding me. What should i do ?
[self.navigationController pushViewController:controller animated:YES];
Try something like this:
// assume controller is UIViewController.
controller.modalPresentationStyle = UIModalPresentationFormSheet;
Then
[self.navigationController presentModalViewController:controller animated:YES];
Check with the below sample working code.
MyModalViewController *targetController = [[[MyModalViewController alloc] init] autorelease];
targetController.modalPresentationStyle = UIModalPresentationFormSheet;
targetController.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal; //transition shouldn't matter
[self presentModalViewController:targetController animated:YES];
targetController.view.superview.frame = CGRectMake(0, 0, 200, 200);//it's important to do this after
presentModalViewController targetController.view.superview.center = self.view.center;
Taken from -->
How to resize a UIModalPresentationFormSheet?

Problem in showing subview as popover

I want to show the subview of a view in popover.
To elaborate,
I have a mainViewController.
I hava a subview 'songListView' in this mainViewController.
I have a button titled 'list' in the mainViewController' itself.
I want to show the songListView in popover on clicking the button 'list'.
So, how should I do this.
You could use the below code as a reference for showing PopOver from a UIButton
-(void) buttonAction:(id)sender {
//build our custom popover view
UIViewController* popoverContent = [[UIViewController alloc]
init];
UIView* popoverView = [[UIView alloc]
initWithFrame:CGRectMake(0, 0, 200, 300)];
popoverView.backgroundColor = [UIColor greenColor];
popoverContent.view = popoverView;
//resize the popover view shown
//in the current view to the view's size
popoverContent.contentSizeForViewInPopover =
CGSizeMake(200, 300);
//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:popoverButton.frame
inView:self.view
permittedArrowDirections:UIPopoverArrowDirectionAny
animated:YES];
//release the popover content
[popoverView release];
[popoverContent release];
}
My problem is solved.
I just created another View Controller class, i.e. 'TempPopoverView'.
Then I set the view of this TempPopoverView equal to the subview of my MainView
Here is the code snippet from my code:
TempPopoverView *viewController = [[TempPopoverView alloc]initWithNibName:#"TempPopoverView" bundle:nil];
[self. songListView setHidden:NO];//songListView is subview of MainView
viewController.view=self. songListView;
UINavigationController *navCont = [[UINavigationController alloc]initWithRootViewController:viewController];
navCont.navigationBar.tintColor = [UIColor colorWithRed:.102 green:.102 blue:.102 alpha:1];
[self showPopOverController:navCont andFrame:sender.frame andInView:self.view];//self.view is the MainView
[viewController release];
[navCont release];
U can use presentModalViewController on your main view.
For example
SongListView *songList = [[SongListView alloc] init];
[self presentModalViewController: songList animated: YES];
There are different animations possible as well.
as simple as you think to add subview in self.view
[popoverController.contentViewController.view addSubview:yourselfobject];