I am trying to load a picture selected on UIImagePickerController on the next view controller. i did some search on similar threads and found a few that helped me set it up, but the image does not really get 'transfered' to the next view controller.
this is my code for the didFinishPickingImage and prepareForSegue:
- (void)imagePickerController:(UIImagePickerController *)picker
didFinishPickingImage:(UIImage *)image
editingInfo:(NSDictionary *)editingInfo
{
self.imageChosen = image;
[picker dismissModalViewControllerAnimated:NO];
[self performSegueWithIdentifier:#"Edit" sender:self];
}
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([segue.identifier isEqualToString:#"Edit"]){
EditViewController *editViewController =
(EditViewController *)segue.destinationViewController;
editViewController.imageView.image = self.imageChosen;
}
I am getting the segue running to the EditViewController, but the imageView there doesnt load the picture. I guess the assignment is wrong somehow but I fail to see how.
When you try to set image to EditViewController UIImageView it doesn't not exist because EditViewController not loaded yet. Instead of setting image to UIImageView directly create an instance variable in EditViewController that will hold image. And than assign this image to UIImageView in viewDidLoad:
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([segue.identifier isEqualToString:#"Edit"]){
EditViewController *editViewController =
(EditViewController *)segue.destinationViewController;
editViewController.image = self.imageChosen;
}
//EditViewController.h
...
#property (nonatomic, strong) UIImage *image;
...
//EditViewController.m
- (void)viewDidLoad {
...
self.imageView.image = self.image;
...
}
Related
So when I press captured button, it's taking a photo and I can save the image in my camera roll. But when I want to see image in another view I can't see it.
This is my code :
- (IBAction)captureButton:(id)sender
{
[self.cameraViewController captureImageWithCompletionHander:^(id data) {
self.image = ([data isKindOfClass:[NSData class]]) ? [UIImage imageWithData:data] : data;
UIImageWriteToSavedPhotosAlbum(self.image, nil, nil, nil);
[self performSegueWithIdentifier:#"savingSegue" sender:self];
}];
}
And this is the prepare for segue method.
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if ([segue.identifier isEqualToString:#"savingSegue"]) {
PhotoSaveViewController *pvc = [[PhotoSaveViewController alloc] init];
[pvc.imageView setImage:self.image];
}
}
It sounds like your destination view controller is a UINavigationController. I'm guessing its top view controller is the one you want. You can access it like this (though you may wish to add type checking):
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if ([segue.identifier isEqualToString:#"savingSegue"]) {
UINavigationController *navigationController = segue.destinationViewController;
PhotoSaveViewController *pvc = (PhotoSaveViewController *)navigationController.topViewController;
[pvc.imageView setImage:self.image];
}
}
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if([segue.identifier isEqualToString:#"savingSegue"])
{
YourNextViewController*ImageView=segue.destinationViewController;
UIImage*clickedImage=capturedPicImageView.image;
ImageView.passedImage=clickedImage;
// NSLog(#"%#",editView.editPhotoImgView.image);
}
}
(And in YourNextViewController create UIImage*clickedImage and give property to it. and dont forget to allocate in viewDidLoad. Hope this helps.
The first view controller calls this method that sends the image
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
...
[wallPostCreateViewController viewDidLoad];
[wallPostCreateViewController selectImage:wallPostCreateViewController.myImage];
NSLog(#"FROM PAWWallViewController %#",wallPostCreateViewController.myImage); //Image is there
}
I receive the image in the second view controller but it fails to put the image into its UIImageView.
- (void)selectImage:(UIImage *)img
{
if (self.condition)
{
NSLog(#"View loaded!"); //is loaded
[self selectImageNow:img];
self.condition = NO;
}
else
NSLog(#"View did NOT load!");
}
- (void)selectImageNow: (UIImage *)img
{
NSLog(#"Image passed %#", img); // This is the UIImage being passed.
self.imageView = [[UIImageView alloc] initWithImage:img];
self.imageView.image = img;
NSLog(#"Image in view %#", self.imageView.image); //has value
NSLog(#"Imageview %#", self.imageView); //has value
}
UPDATED:
The code above is updated now. All of the logs now have values but I still see no image or image view when I run the app
The issue seems like your imgView is nil. So make sure that your method should not get called, before your view has been loaded.
Send UIImage object from one to another ViewController then assign that UIImage to UIImageViewin ViewWillAppear OR ViewDidLoad method of SecondController.
I think you need to set the imageView of first view controller in prepareForSegue method that is in the second view controller, where you will have your destination to be the first view controller, do something like this in the second view controller:
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{
if([segue.identifier isEqualToString:#"firstVwCtrl"]){
FirstViewController *frstVwCtrl = [segue destinationViewController];
[frstVwCtrl setImgGot:_photoView.image];
} }
I have a drawing app with begins with choosing a category. Every category has his own drawing template. How do I get the secondViewController, to load the correct template? The category is chosen true a button from the firstViewController.
I have managed to give each segue a own identifier. And then what?
I only find examples of ways to parse data or images. But I don't want it to parse. I want it to load the image only on the secondViewController.
SecondViewController.h File
#property (strong, nonatomic) UIImage *theCatImage;
SecondViewController.m File
#interface secondViewController()
#property (weak, nonatomic) IBOutlet UIImageView *image;
#end
#implementation secondViewController
- (void)viewDidLoad
{
[super viewDidLoad];
self.image.image = self.theCatImage;
}
ViewController.h File
#import <UIKit/UIKit.h>
#import "cat01ViewController.h"
#interface ikzieikzieAppViewController : UIViewController
#property (weak, nonatomic) IBOutlet UIImageView *newImage;
#end
ViewController.m File
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{
if ([segue.identifier isEqualToString:#"vervoer"]) {
cat01ViewController *secondView = (cat01ViewController *)segue.destinationViewController;
// dont know what to send here... i tried to hide and show a image like this;
secondView.theCatImage = self.newImage;
}
}
EDIT
Above code doesn't work, ALSO i don't want to send a image from one to another viewcontroller.
This is what i want;
On the firstViewController, a user can choose from four different categories. Each categorie will show his own drawing template and also, gives his own ID when the drawing is send to a parse database at the end.
So, what is the best way to set this up?
***SOLUTION***
Eventually, this is the way i solved it.
ViewController
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([segue.identifier isEqualToString:#"vervoer"]) {
UIImage *image = [UIImage imageNamed:#"vervoer.png"];
cat01ViewController *vc = [segue destinationViewController];
vc.showImage = image;
}
else if ([segue.identifier isEqualToString:#"huis"]) {
UIImage *image = [UIImage imageNamed:#"huis.png"];
cat01ViewController *vc = [segue destinationViewController];
vc.showImage = image;
}
else if ([segue.identifier isEqualToString:#"mode"]) {
UIImage *image = [UIImage imageNamed:#"vinkje.png"];
cat01ViewController *vc = [segue destinationViewController];
vc.showImage = image;
}
else if ([segue.identifier isEqualToString:#"eten"]) {
UIImage *image = [UIImage imageNamed:#"bord.png"];
cat01ViewController *vc = [segue destinationViewController];
vc.showImage = image;
}
}
SecondViewController
#synthesize catImage, showImage;
- (void)viewDidLoad
{
[catImage setImage:showImage];
[super viewDidLoad];
}
What you want to do is to add a property on SecondViewController:
#property (nonatomic) int category;
Then inside FirstViewController
Add property
#property (nonatomic) int chosenCategory;
Set this to the category that the user selected.
Then inside your seque code:
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{
cat01ViewController *secondView = (cat01ViewController *)segue.destinationViewController;
[secondView setCategory:self.chosenCategory];
}
This will tell the VC which image it will need to draw. Then you call your parse library method to retrieve the image based on the ID (Category) chosen inside the viewDidLoad method in SecondViewController:
SecondViewController
- (void)viewDidLoad
{
[super viewDidLoad];
self.image.image = [ParseLibrary getImageForCategory:self.chosenCategory];
}
I have 2 simple views in my Storyboard and both use the same ViewController. I have the following code to switch the the second view...
self.labelStatus.text = #"CHECKING";
[self performSegueWithIdentifier:#"LoginSuccess" sender:sender];
*labelStatus is on the second view.
For some reason the labels text is not changing. Can anyone advise why this is?
[self performSegueWithIdentifier:#"LoginSuccess" sender:sender];
//change the label value in prepareForSegue: method
- (void)prepareForSegue:(UIStoryboardSegue *)segue {
if ([segue.identifier isEqualToString:#"LoginSuccess"]) {
UIViewController *loginVC = segue.destinationViewController;
//declare the string in .h file and assign it in viewDidLoad in loginVC
loginVC.labelString = #"CHECKING";
}
}
in loginViewController.h file
#property(nonatomic, strong) NSString *labelString;
in loginViewController.m file
- (void)viewDidLoad
{
[super viewDidLoad];
self.labelStatus.text = labelString
}
You can customise your destinationViewController (properties, views, etc) in prepareForSegue: method, which is called before segue is executed:
- (void)prepareForSegue:(UISegue *)segue {
if ([segue.identifier isEqualToString:#"mySegue"]) {
UIViewController *destVC = segue.destinationViewController;
// do your customisation
}
}
Edit-
If you need to change the label in the same view controller, then you should modify the label in the prepareForSegue method.
I'm using the library GKClass, its basically a custom imagePickerController class.
I'm having trouble passing data - the image to the next control view, while it was working with the simple imagePickerController its not working now, the ViewController doesn't get the data.
-(void)imagePicker:(GKImagePicker *)imagePicker pickedImage:(UIImage *)image
{
VCImageEditingViewController *ieVC = [[VCImageEditingViewController alloc]init];
ieVC.selectedIMG = image;
[self.imagePicker.imagePickerController dismissViewControllerAnimated:NO completion:nil];
[self performSegueWithIdentifier:#"imgrdy" sender:self];
}
and VCImageEditingViewController.m:
- (void)viewDidLoad
{
[super viewDidLoad];
if (self.selectedIMG == nil) {
NSLog(#"no img set");
}
self.imageDisplayed.image = self.selectedIMG;
}
i tried it also in viewDidAppear and still nothing, the "picker" is working since iv tried :
-(void)imagePicker:(GKImagePicker *)imagePicker pickedImage:(UIImage *)image
{
[self.imagePicker.imagePickerController dismissViewControllerAnimated:NO completion:nil];
self.lastImageView.image = image;
}
It showed the image in the current view controller.
My guess is that the destination viewController is presented before the image is modified.
Would like some help here. Thank you.
Try this
-(void)imagePicker:(GKImagePicker *)imagePicker pickedImage:(UIImage *)image
{
[self.imagePicker.imagePickerController dismissViewControllerAnimated:NO completion:nil];
//pass image with peroformsegue
[self performSegueWithIdentifier:#"imgrdy" sender: image];
}
// In prepare segue method assign image to destination view controller
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([[segue identifier] isEqualToString:#"imgrdy"])
{
VCImageEditingViewController *ieVC=segue.destinationViewController;
ieVC.selectedIMG =(UIImage *) sender;
}
}