Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 11-26-2011, 06:15 PM   #1 (permalink)
Registered Member
 
Join Date: Nov 2011
Posts: 7
s4lfish is on a distinguished road
Default Pass UIImage between ViewControllers

Hi,

I'm trying to pass an UIImage from one UIView in UITabBarController1 to another UIView in UINavigationController in UITabBarController2. In View1 i tried this:

Code:
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingImage:(UIImage *)image editingInfo:(NSDictionary *)editingInfo
{

    UploadModifyViewController *view2 = [self.storyboard instantiateViewControllerWithIdentifier:@"modify"];
    UITabBarController *navBar = [self.storyboard instantiateViewControllerWithIdentifier:@"navBar"];
    view2.imageView.image = image;                //<-----
    [self dismissModalViewControllerAnimated:NO];
    [self presentModalViewController:navBar animated:YES];
}
Remember, view2 is in a NavigationController, and NavigationController is in a TabBarController. Extern Variable doesn't work, because these can't be used with UI Elements.

I also tried to declare an UIImage in the UploadModifyViewController.h and store the image with view2.image = storedImage; and then in the viewDidLoad of view2 i tried to set self.imageView = storedImage but this also didn't work.

Somehow the stored image gets lost when view2 gets initialized by its NavigationController.

Greetz
s4lfish
s4lfish is offline   Reply With Quote
Old 11-27-2011, 09:45 PM   #2 (permalink)
Registered Member
 
Join Date: Oct 2011
Posts: 34
jmktayag is on a distinguished road
Default

Quote:
Originally Posted by s4lfish View Post
Hi,

I'm trying to pass an UIImage from one UIView in UITabBarController1 to another UIView in UINavigationController in UITabBarController2. In View1 i tried this:

Code:
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingImage:(UIImage *)image editingInfo:(NSDictionary *)editingInfo
{

    UploadModifyViewController *view2 = [self.storyboard instantiateViewControllerWithIdentifier:@"modify"];
    UITabBarController *navBar = [self.storyboard instantiateViewControllerWithIdentifier:@"navBar"];
    view2.imageView.image = image;                //<-----
    [self dismissModalViewControllerAnimated:NO];
    [self presentModalViewController:navBar animated:YES];
}
Remember, view2 is in a NavigationController, and NavigationController is in a TabBarController. Extern Variable doesn't work, because these can't be used with UI Elements.

I also tried to declare an UIImage in the UploadModifyViewController.h and store the image with view2.image = storedImage; and then in the viewDidLoad of view2 i tried to set self.imageView = storedImage but this also didn't work.

Somehow the stored image gets lost when view2 gets initialized by its NavigationController.

Greetz
s4lfish
Instead of passing it to the property of imageView try to create a UIImage variable and pass the image to the UIImage that you have declared and instantiate it with your imageView.
jmktayag is offline   Reply With Quote
Old 11-27-2011, 10:31 PM   #3 (permalink)
Just helping out.
 
Domele's Avatar
 
Join Date: Feb 2011
Posts: 2,565
Domele is on a distinguished road
Default

You should never mess with a view controller's view. A reason for that is you don't know if its view is created yet. jmktayag's solution is perfect.
__________________
If you are looking for a quality developer, I'm your man. Give me a PM if you are interested.

New app - See screenshots and details at www.globaclock.com.

If you want to thank me, click the link. Every click counts. If you want to do more, buy my app. A link is available on my website. Thanks.
Domele is offline   Reply With Quote
Old 11-28-2011, 03:24 AM   #4 (permalink)
Registered Member
 
Join Date: Nov 2011
Posts: 7
s4lfish is on a distinguished road
Default

Thank you for your answers.

But can u give me a hint how this would look like? I'm new to iOS development
I declare an UIImage in ... the UploadModifyViewController?
And in the viewDidLoad i try self.imageView instatiateWithImage:image ?

Greetz

S4lfish
s4lfish is offline   Reply With Quote
Old 11-28-2011, 03:43 AM   #5 (permalink)
Registered Member
 
Join Date: Oct 2011
Posts: 34
jmktayag is on a distinguished road
Default

Quote:
Originally Posted by s4lfish View Post
Thank you for your answers.

But can u give me a hint how this would look like? I'm new to iOS development
I declare an UIImage in ... the UploadModifyViewController?
And in the viewDidLoad i try self.imageView instatiateWithImage:image ?

Greetz

S4lfish

After passing the image from the previous controller to your UploadModifyViewController you can use self.imageView.image = myImage.
Your UIImage declaration must be synthesized.
jmktayag is offline   Reply With Quote
Old 11-28-2011, 05:35 AM   #6 (permalink)
Registered Member
 
Join Date: Nov 2011
Posts: 7
s4lfish is on a distinguished road
Default

Mhh, i think i already tried this.
Perhaps i screwed something in the Storyboard up ...
i post a screenshot that u can see what I'm trying to do:



1, Class: UploadViewController
When u choose an image from the library, the image should be shown in the imageView of 4.
In this controller:
Code:
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingImage:(GEOImage *)image editingInfo:(NSDictionary *)editingInfo
{
    
    
    UploadTabBar *tabBar = [self.storyboard instantiateViewControllerWithIdentifier:@"tabBar"];
    UploadModifyViewController *modifyView = [self.storyboard instantiateViewControllerWithIdentifier:@"modify"];
    modifyView.chosenImage = image;
    
    [self dismissModalViewControllerAnimated:NO];
    [self presentModalViewController:tabBar animated:YES];
2, Class: UploadTabBarController (only exists because i tried almost everywhere to store the image^^)
Here i'd like to store the Image, because i want to add some image description, GPS tag and so on in the other 2 Tabs of TabBarController, and gather all information in the TabBarController.

3, Class: UploadNavBarController (same here as 2)

4, Class: UploadModifyViewController
in the .h :
Code:
UIImage *chosenImage;
              UIImageView *imageView;
@property (nonatomic, retain) UIImage *chosenImage
@property (nonatomic, retain) IBOutlet UIImageView *imageView;
In the viewDidLoad: self.imageView.image = chosenImage;
Attached Images
File Type: jpg Bildschirmfoto 2011-11-28 um 12.07.51 Kopie.jpg (9.0 KB, 38 views)

Last edited by s4lfish; 11-28-2011 at 11:27 AM.
s4lfish is offline   Reply With Quote
Old 11-29-2011, 12:08 AM   #7 (permalink)
Registered Member
 
Join Date: Oct 2011
Posts: 34
jmktayag is on a distinguished road
Default

Quote:
Originally Posted by s4lfish View Post
Mhh, i think i already tried this.
Perhaps i screwed something in the Storyboard up ...
i post a screenshot that u can see what I'm trying to do:



1, Class: UploadViewController
When u choose an image from the library, the image should be shown in the imageView of 4.
In this controller:
Code:
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingImage:(GEOImage *)image editingInfo:(NSDictionary *)editingInfo
{
    
    
    UploadTabBar *tabBar = [self.storyboard instantiateViewControllerWithIdentifier:@"tabBar"];
    UploadModifyViewController *modifyView = [self.storyboard instantiateViewControllerWithIdentifier:@"modify"];
    modifyView.chosenImage = image;
    
    [self dismissModalViewControllerAnimated:NO];
    [self presentModalViewController:tabBar animated:YES];
2, Class: UploadTabBarController (only exists because i tried almost everywhere to store the image^^)
Here i'd like to store the Image, because i want to add some image description, GPS tag and so on in the other 2 Tabs of TabBarController, and gather all information in the TabBarController.

3, Class: UploadNavBarController (same here as 2)

4, Class: UploadModifyViewController
in the .h :
Code:
UIImage *chosenImage;
              UIImageView *imageView;
@property (nonatomic, retain) UIImage *chosenImage
@property (nonatomic, retain) IBOutlet UIImageView *imageView;
In the viewDidLoad: self.imageView.image = chosenImage;
I'm not quite still familiar with the storyboard thing. Can you check if the UploadModifyViewController is properly initialize? You could use NSLog to show if the controller's state.
jmktayag is offline   Reply With Quote
Old 11-29-2011, 06:44 AM   #8 (permalink)
Registered Member
 
Join Date: Nov 2011
Posts: 7
s4lfish is on a distinguished road
Default

Mhh, how can i view the Controller states?

I already tried to store the image in the AppDelegate as UIImage
with properties:
Code:
@property (nonatomic, copy) UIImage *chosenImage;
and then in the Upload Class:
Code:
AppDelegate *appD = (AppDelegate *) [[UIApplication sharedApplication] delegate];
appD.chosenImage = image;
I am doing it wrong? Because when i try to load in the ModifyViewController's viewDidLoad{} with
Code:
AppDelegate *appD = (AppDelegate *) [[UIApplication sharedApplication] delegate];
    self.imageView.image = appD.chosenImage;
...it still doesn't work.
s4lfish is offline   Reply With Quote
Old 11-29-2011, 08:44 AM   #9 (permalink)
Registered Member
 
Join Date: Nov 2011
Posts: 3
Jessica1988 is on a distinguished road
Default

The man has great knowledge
Jessica1988 is offline   Reply With Quote
Old 11-30-2011, 11:47 AM   #10 (permalink)
Registered Member
 
Join Date: Nov 2011
Posts: 7
s4lfish is on a distinguished road
Default

No one has an idea? And please no senseless posts like the one above ...

Tried to figure out when and how the controllers initialize or instantiate the view, but got no solution yet
s4lfish is offline   Reply With Quote
Old 11-30-2011, 08:42 PM   #11 (permalink)
Registered Member
 
Join Date: Oct 2011
Posts: 34
jmktayag is on a distinguished road
Default

Quote:
Originally Posted by s4lfish View Post
No one has an idea? And please no senseless posts like the one above ...

Tried to figure out when and how the controllers initialize or instantiate the view, but got no solution yet
Instead of copy could you try retain?
jmktayag is offline   Reply With Quote
Reply

Bookmarks

Tags
ios, uiimage, viewcontroller

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 405
15 members and 390 guests
chiataytuday, Clouds, David-T, dedeys78, Duncan C, e2applets, EvilElf, iekei, ipodphone, leostc, LunarMoon, Murphy, sacha1996, Sami Gh, teebee74
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,676
Threads: 94,127
Posts: 402,912
Top Poster: BrianSlick (7,990)
Welcome to our newest member, jleannex55
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 06:39 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0