Is it possible to show UIViewController as popover in iphone - ios

I have created a UIViewController using Interface Builder is it possible to view the UIViewController as a popover of specified size.
The size of my UIViewController is default 600X600 since I am using size classes.
I have tried various answers available but none works for me.

For Showing Popover in Phone Just Make Category of UIPopoverController Code :
// UIPopoverController+iPhone.h
#import <UIKit/UIKit.h>
#interface UIPopoverController (iPhone)
+ (BOOL)_popoversDisabled;
#end
// UIPopoverController+iPhone.m
#import "UIPopoverController+iPhone.h"
#implementation UIPopoverController (iPhone)
+ (BOOL)_popoversDisabled {
return NO;
}
#end
and just import this category where you required. and show popover as you show for iPAD.
-(IBAction)showPopOver:(id)sender {
TestPopOver *tstPop = [self.storyboard instantiateViewControllerWithIdentifier:#"TestPopOver"];
popOverController = [[UIPopoverController alloc]initWithContentViewController:tstPop];
popOverController.popoverContentSize = CGSizeMake(300.0, 300.0);
[popOverController presentPopoverFromRect:[(UIButton *)sender frame]
inView:self.view
permittedArrowDirections:UIPopoverArrowDirectionAny
animated:YES]; }

Related

UIPopovercontroller doesn't show anything on iPad Simulator(xCode6.1)

I am trying to show the UIPopovercontroller that involves UIPickerView when I click a button on iPad. I can see the UIPopovercontroller but I can't see the UIPickerView in UIpopovercontroller
I've already made a ViewController which has the UIPickerViewer in storyboard for UIPopovercontroller.
So what am I missing now?
Here are the code I am using.
#property (nonatomic, strong) UIPopoverController *userDataPopover;
- (IBAction)setTime:(id)sender {
DatePickerViewController *viewController = [self.storyboard instantiateViewControllerWithIdentifier:#"datePickerView"];
viewController.delegate = self;
self.userDataPopover = [[UIPopoverController alloc] initWithContentViewController:viewController];
self.userDataPopover.popoverContentSize = CGSizeMake(400, 400);
[self.userDataPopover presentPopoverFromRect:[(UIButton *)sender frame]
inView:self.view
permittedArrowDirections:UIPopoverArrowDirectionAny
animated:YES]; }
Try these
0 - Check height of date picker.
1 - Check constraints if you have any.
2 - Can you try to add DatePicker directly to popover controller
when I use following code, it works well.
DatePickerViewController *viewController = [self.storyboard instantiateViewControllerWithIdentifier:#"datePickerView"];
[self presentViewController:viewController animated:YES completion:nil]
But there is a problem when I use Popovercontroller.

UIPopoverview for iPhone,iOS 7

I need popover view. i followed this instructions.
Init: Create two UIViewController in storyboard.
lets say FirstViewController which is normal and SecondViewController Which we make Popup.
Model Segue: Put UIButton In FirstViewController and create a segue on this UIButton to SecondViewController as model segue.
Make Transparent: Now selet UIView (UIView Which is created by default with UIViewController) of SecondViewController and change its background color to clear color.
Make background Dim: Add a UIImageView in SecondViewController which cover hole screen and sets its image to some dimmed semi transparent image. You can get a sample from here : UIAlertView Background Image
Display Design: Now Add a UIView and make and kind of design you want to show. Here I have shown screen shot of my storyboard.
Here I have add segue on login button which open SecondViewController as popup to ask username and password
Important: Now that main step. We want that SecondViewController dont hide FirstViewController completely. We have set clear color but this is not enough. By default it add black behind model presentation So we have to add one line of code in viewDidLoad of FirstViewController. You can add it at other place also but it should run before segue.
[self setModalPresentationStyle:UIModalPresentationCurrentContext];
Dismiss: When to dismiss is depend on you. This is a model presentation so to dismiss we do what we do for model presentation:
[self dismissViewControllerAnimated:YES completion:Nil];
But am USING NAVIGATION CONTROLLER,, for that transparent background is not coming?????
Kindly help me..!!!! My screen shot is below.
create one view controller in freeform mode just like following image
in your first view controller add the one UIButton just like the following image
in your first view controller.h add the following line
#import "UIPopoverController+iPhone.h"
#interface first view controller : UIViewController<UIPopoverControllerDelegate>
#property (nonatomic,strong) UIPopoverController *popOver;
#property (strong, nonatomic) IBOutlet UIButton *popbtn;
in your first view controller.m add the following line to the button action method
- (IBAction)popButton:(UIButton *)sender
{
UILabel *showlblView=[[UILabel alloc]init];
showlblView.frame=CGRectMake(10, 10, 250, 40);
showlblView.text=#"Gopi";
showlblView.textColor=[UIColor whiteColor];
showlblView.textAlignment=NSTextAlignmentCenter;
final *vc=[[final alloc] init];
[vc.view addSubview:showlblView];
self.popOver=[[UIPopoverController alloc]initWithContentViewController:vc];
[self.popOver setPopoverContentSize:CGSizeMake(300, 200)];
CGRect popoverframe=CGRectMake(self.popbtn.frame.origin.x, self.popbtn.frame.origin.y, self.popbtn.frame.size.width, self.popbtn.frame.size.height);
[self.popOver presentPopoverFromRect:popoverframe inView:self.view permittedArrowDirections:UIPopoverArrowDirectionUp animated:YES];
}
here ur NSObjet class file UIPopoverController+iPhone.h
.h file
#import <UIKit/UIKit.h>
#interface UIPopoverController (iPhone)
+ (BOOL)_popoversDisabled;
#end
.m file
#import "UIPopoverController+iPhone.h"
#implementation UIPopoverController (iPhone)
+ (BOOL)_popoversDisabled {
return NO;
}
#end
the full project code is available at the following link :
https://www.sendspace.com/file/ktie4t
i had the same problem and didn't find solution how to solve it with segue on storyboard, but programmatically it's work fine, when i presenting second controller on first controller (that pushed with navigationViewController). if it's not critical for you, try this:
+ (void)showWithParent:(UIViewController *)parentController {
static SomeViewController *singleton = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"Main" bundle:nil];
singleton = [storyboard instantiateViewControllerWithIdentifier:#"SomeViewControllerID"];
});
[parentController presentViewController:singleton animated:YES completion:nil];
}
or just:
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"Main" bundle:nil];
SecondViewController *secondController = [storyboard instantiateViewControllerWithIdentifier:#"SecondViewControllerID"];
[firstController presentViewController:secondController animated:YES completion:nil];

delegate help code not behaving as expected

Really simple question i think.
i have a main view and a popover view.
i am trying to make a custom delegate which will enable me to close the popover view at certain times. My code is posted below. The real simple issue i am having is my code dosnt appear to be entering the delegate code. Any ideas as to why? It builds and runs but nothing appears to happen, i have put NSLog statments, the popover nslog appears but the function in
mainview dismissPopover does nothing.
Mainview.h
#interface MainScreen : UIViewController<DismissPopoverDelegate>
Mainview.m
- (void) dismissPopover:(NSNumber *)dataa
{ /* Dismiss you popover here and process data */
[popoverController dismissPopoverAnimated:YES];
NSLog(#"OLOLO");
}
Popover.h
#protocol DismissPopoverDelegate
- (void) dismissPopover:(NSNumber *)yourDataToTransfer;
#end
#interface SelectAgePopOver : UIViewController<UITableViewDataSource,
UITableViewDelegate,UIPopoverControllerDelegate>{
NSArray *items;
id<DismissPopoverDelegate> delegate;
}
#property (nonatomic, assign) id<DismissPopoverDelegate> delegate;
Popover.m
[self.delegate dismissPopover:selrow];
where i want the delegate called.
Thanks
the popover view is called by the following method in main view.m
controller = [[SelectAgePopOver alloc] initWithNibName:#"SelectAgePopOver" bundle:nil];
popoverController = [[UIPopoverController alloc] initWithContentViewController:controller];
[popoverController setDelegate:self];
popoverController.popoverContentSize = CGSizeMake(250, 294);
if ([popoverController isPopoverVisible]) {
[popoverController dismissPopoverAnimated:YES];
} else {
CGRect popRect = CGRectMake((self.AgeRangeTextField.frame.origin.x+50),
(self.AgeRangeTextField.frame.origin.y+50),
(self.AgeRangeTextField.frame.size.width),
(self.AgeRangeTextField.frame.size.height));
[popoverController presentPopoverFromRect:popRect inView:self.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
}
}
On where you instantiate the instance of the SelectAgePopOver, you need to set the delegate of the SelectAgePopOver instance to the MainScreen (self) in the Mainview.m, for example:
controller = [[SelectAgePopOver alloc] initWithNibName:#"SelectAgePopOver" bundle:nil];
;
controller.delegate = self;
Please try to set the controller delegate as shown above.
In the SelectAgePopOver.h class file, you do not need to set UIPopOverControllerDelegate though.

Present UINavigationController from UIViewController

CurrentViewController.h
#import <UIKit/UIKit.h>
#import "nextNavViewController.h"
#interface CurrentViewController : UIViewController
{
nextNavViewController *contr;
}
- (IBAction)showNavView:(id)sender;
#end
CurrentViewController.m
/*..........*/
- (IBAction)showNavView:(id)sender {
contr = [[nextNavViewController alloc]initWithNibName:#"nextNavViewController"bundle:nil];
[self presentViewController: contr animated:YES completion:nil];
}
/* ......... */
nextNavViewController.h
#import <UIKit/UIKit.h>
#interface nextNavViewController : UINavigationController
#end
I have "nextNavViewController.xib" which contains a table , some buttons and customized navigation bar. I want this interface to be loaded but it loads blank navbar with blank screen.
Is the thing i am doing possible? What i have to do to load the customized interface??
A couple of things:
1) Careful with the name of your classes. Make sure they follow the objective-c standards
2) You don't need to sub-class a UINavigationController. If you want to receive some of the capabilities of a UINavigationController, just:
contr = [[nextNavViewController alloc]initWithNibName:#"nextNavViewController"bundle:nil];
UINavigationController *myNavigation = [[UINavigationController alloc] initWithRootViewController:contr];
[self presentViewController:myNavigation animated:YES completion:nil];

How to access the photo from the library in iPad?

I want to access the iPad photo library and retrieve the image and display it in a image-view.
use Assets Library Framework
http://www.icodeblog.com/2010/10/07/cloning-uiimagepickercontroller-using-the-assets-library-framework/
Are you looking for help with the UIImagePickerController?
http://trailsinthesand.com/picking-images-with-the-iphone-sdk-uiimagepickercontroller/
The iPad equivalent of an UIImagePickerController is a UIPopoverController. This YouTube video shows a basic implementation: http://www.youtube.com/watch?v=gaaLMKuPwfU. I just added a check so that only one Popover is present at a time; see if (pop.isPopoverVisible == TRUE) below. And the video shows how to connect up the button using Interface Builder. (And obviously, you'll need images on your device or simulator for this to work.) Hope it helps.
The header file:
#import <UIKit/UIKit.h>
#interface MyViewController : UIViewController <UIPopoverControllerDelegate, UINavigationControllerDelegate, UIImagePickerControllerDelegate>
{
}
- (IBAction)barBtn1:(id)sender;
#end
The implementation file:
#import "MyViewController.h"
#implementation MyViewController
- (IBAction)barBtn1:(id)sender
{
UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
[imagePicker setDelegate:self];
// If user selects button while previous pop is visible, dismiss previous pop.
if (pop.isPopoverVisible == TRUE)
{
[pop dismissPopoverAnimated:YES];
}
UIPopoverController *pop = [[UIPopoverController alloc] initWithContentViewController:imagePicker];
[pop setDelegate:self];
[pop presentPopoverFromBarButtonItem:sender permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
[imagePicker release];
}

Resources