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];
}
Related
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]; }
I'm trying to detect when a UIPopoverController gets dismissed, but it seems not to work properly, the methods are not getting called. This is my code for presenting the UIPopoverController:
UIImagePickerController *imagePickerController = [[UIImagePickerController alloc] init];
imagePickerController.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
imagePickerController.delegate = self;
UIPopoverController *popoverVC = [[UIPopoverController alloc] initWithContentViewController:imagePickerController];
popoverVC.delegate = self;
[popoverVC presentPopoverFromRect:CGRectMake(self.frame.origin.x,self.frame.origin.y, self.frame.size.width, self.frame.size.height) inView:[home view] permittedArrowDirections:0 animated:YES];
I'm trying to fire this method, but is not getting called:
- (void) popoverControllerDidDismissPopover:(UIPopoverController *) popoverController;
And I'm indeed adding the delegate to the header:
#interface Map : UIView <UIImagePickerControllerDelegate, UINavigationControllerDelegate, UIGestureRecognizerDelegate, UIScrollViewDelegate,UIPopoverControllerDelegate>
I don't know what I'm missing out, is not working at all.
You probably already solved it, but I just faced the same problem. I'm holding a instance of UIPopoverController in my Viewcontroller and had it this way:
self.popover.delegate = self;
self.popover = [[UIPopoverController alloc] initWithContentViewController:wgtvc];
of course this doesn't work because I'm initializing the UIPopoverController AFTER setting the delegate, which overrides the delegate setting. So the correct way is to FIRST initialize the UIPopovercontroller and THEN setting the delegate
self.popover = [[UIPopoverController alloc] initWithContentViewController:wgtvc];
self.popover.delegate = self;
Maybe you are reinitializing your UIPopoverController somewhere - just set the delegate again after reinitializing.
Hpoe this helps.
So, I figured out how to make it work.
I made a "global" variable for the class.
self.popoverVC = [[UIPopoverController alloc] initWithContentViewController:imagePickerController];
self.popoverVC.delegate = self;
Because it's an UIImagePickerController inside a UIPopoverController, I needed to listen to the UIImagePickerController for dismission too and combine both methods:
- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker;
- (void) popoverControllerDidDismissPopover:(UIPopoverController *) popoverController
So I can now detect when the UIPopoverController gets dismissed.
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.
I am creating image based application.Now I have allocated and synthesized pickerviewcontroller in my viewcontroller.m class.
as UIImagePickerController *picker. Here I have Give it to the (IBAction).
-(IBAction)selectphoto:(id)sender
{
picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.allowsEditing = YES;
picker.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;
[self presentViewController:picker animated:YES completion:NULL];
}
Then i have set it`s delegate methods.
Now, In my another class named as imagedisplay.m,I have created one Button, at which i want to create popupviewcontroller with my imagepickercontroller images(which is in my viewcontroller class),
Below is my code,
-(IBAction)gallery:(id)sender
{
NSLog(#"pop over done.");
ViewController *vcntrlr = [[ViewController alloc] init];
UIPopoverController *popover_=[[UIPopoverController alloc] initWithContentViewController:vcntrlr.picker];
[popover_ setDelegate:self];
[popover_ presentPopoverFromRect:CGRectMake(100, 280,100,100) inView:self.view permittedArrowDirections:UIPopoverArrowDirectionUp animated:YES];
}
I expecting for Displaying popover controller.BUt when i tryng to press Button((IBAction)gallery) my application is terminated and seems below error.
"terminating with uncaught exception of type NSException".
Help me .
My first guess would be that you are not holding any strong reference to the popovercontroller, so it will be released outside the scope of the -(IBAction)gallery:(id)sender method. To ensure the popover controller is kept alive after the method has finished, you should keep a strong reference to it.
To do so you can add a property to your class:
#property (strong, nonatomic) UIPopoverController* popoverController;
And change your code into:
self.popoverController = [[UIPopoverController alloc] initWithContentViewController:vcntrlr.picker];
[self.popoverController setDelegate:self];
[self.popoverController presentPopoverFromRect:CGRectMake(100, 280,100,100) inView:self.view permittedArrowDirections:UIPopoverArrowDirectionUp animated:YES];
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.