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

Mockup & CodeGen, iPhone & iPad
($9.99)

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

Manu
($0.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 06-21-2009, 11:39 PM   #1 (permalink)
Registered Member
 
Join Date: Jun 2009
Posts: 8
Default Help Retaining UIImage

Hi all, I'm working on my first iPhone app and I ran into a problem. Here's what I got...

I have a Navigation-Based app where each cell in the table has a UILabel and a UIImageView. Tapping a cell goes to a ViewController where the data from the UILabel and UIImageView can be modified. In this ViewController there is a text field, a UIImageView and a Button which calls up the built-in ImagePickerController.

Whenever I add/modify an item and return to the TableView, the UILabel is showing the appropriate changes. However, I can't seem to get the image "out" of the ViewController and back to the TableView. I did some checking and it seems that the image is simply nil whenever I go back to the TableView.

Here's my code...

ViewController:
Code:
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingImage:(UIImage *)image editingInfo:(NSDictionary *)editingInfo
{
    imageView.image = image; //UIImageView in the ViewController is updated successfully
    self.item.itemPic = image; //itemPic set. a check confirmed it's not nil

    [picker dismissModalViewControllerAnimated:YES];
}
- (IBAction) updateName:(id) sender
{
    self.item.itemName = self.itemNameTextField.text;
}
ItemCell:
Code:
- (void)setItem:(Item *)newItem
{
    item = newItem;

    self.itemNameLabel.text  = newItem.itemName; //this works fine.
    self.itemImageView.image = newItem.itemPic; //itemPic is nil

    [self setNeedsDisplay];
}
Anybody have any ideas? ANY help would be greatly appreciated.
Errornix is offline   Reply With Quote
Old 06-22-2009, 09:07 AM   #2 (permalink)
Registered Member
 
Join Date: Apr 2009
Location: Madurai
Posts: 111
Send a message via MSN to lokidil Send a message via Yahoo to lokidil Send a message via Skype™ to lokidil
Default

Quote:
Originally Posted by Errornix View Post
Hi all, I'm working on my first iPhone app and I ran into a problem. Here's what I got...

I have a Navigation-Based app where each cell in the table has a UILabel and a UIImageView. Tapping a cell goes to a ViewController where the data from the UILabel and UIImageView can be modified. In this ViewController there is a text field, a UIImageView and a Button which calls up the built-in ImagePickerController.

Whenever I add/modify an item and return to the TableView, the UILabel is showing the appropriate changes. However, I can't seem to get the image "out" of the ViewController and back to the TableView. I did some checking and it seems that the image is simply nil whenever I go back to the TableView.

Here's my code...

ViewController:
Code:
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingImage:(UIImage *)image editingInfo:(NSDictionary *)editingInfo
{
    imageView.image = image; //UIImageView in the ViewController is updated successfully
    self.item.itemPic = image; //itemPic set. a check confirmed it's not nil

    [picker dismissModalViewControllerAnimated:YES];
}
- (IBAction) updateName:(id) sender
{
    self.item.itemName = self.itemNameTextField.text;
}
ItemCell:
Code:
- (void)setItem:(Item *)newItem
{
    item = newItem;

    self.itemNameLabel.text  = newItem.itemName; //this works fine.
    self.itemImageView.image = newItem.itemPic; //itemPic is nil

    [self setNeedsDisplay];
}
Anybody have any ideas? ANY help would be greatly appreciated.
Hey check out this http://www.iphonedevsdk.com/forum/ip...ry-issues.html it will help U!!!
lokidil is offline   Reply With Quote
Old 06-22-2009, 11:46 AM   #3 (permalink)
Registered Member
 
Join Date: Jun 2009
Posts: 8
Default

Thanks for that link. I didn't even realize that memory leak was in my app!

Unfortunately, I don't think the information there helps with my problem (unless I missed something). I'm having this problem even when there's only one record with one image, so I don't think my issue is memory-management related.


My problem is simply this: In my ViewController, I can set the text and image values of my Item to my TextField and UIImage successfully. When I try to get these two values "out" on the ViewController and into the Item in my TableView, only the TextField is being populated.

So is there some special method required here when dealing with UIImages? Is this simply not possible for whatever reason? Or am I just overlooking something simple and stupid?
Errornix is offline   Reply With Quote
Old 06-22-2009, 02:15 PM   #4 (permalink)
jsd
at this moment
 
Join Date: Mar 2009
Location: San Francisco, CA
Posts: 900
Default

you don't provide enough context to explain for sure but it seems like you just aren't storing the image anywhere. how does newItem get passed into setItem? are these separate classes/objects?
jsd is offline   Reply With Quote
Old 06-23-2009, 09:48 PM   #5 (permalink)
Registered Member
 
Join Date: Jun 2009
Posts: 8
Default

I fixed it. I didn't have @synthesize item in ItemCell.m

So now I have that part working, but I've also run into a new issue. I'm able to select an image using the UIImagePickerController and then save the image. However, whenever I restart the app and load the saved image, it's turned -90 degrees!

This only happens with images that were selected from the picker. Images taken with the camera within the app seem to be fine. Also, I'm only seeing this on the iPhone itself, the simulator isn't having any issues.

I don't know what I could be doing wrong since the same code is saving both the selected images and the camera images. Is this a known problem with the iPhone? I tried Googling, but all of the results were about how to get an image to rotate, so that didn't help.
Errornix is offline   Reply With Quote
Old 06-23-2009, 11:46 PM   #6 (permalink)
Registered Member
 
Join Date: Apr 2009
Location: Madurai
Posts: 111
Send a message via MSN to lokidil Send a message via Yahoo to lokidil Send a message via Skype™ to lokidil
Default

Hey try this [image CGImage]; this will give u a actual image,
Otherwise the problem is with Context check for context is changing the image properties!!!
lokidil is offline   Reply With Quote
Old 06-24-2009, 07:52 PM   #7 (permalink)
Registered Member
 
Join Date: Jun 2009
Posts: 8
Default

Quote:
Originally Posted by lokidil View Post
Hey try this [image CGImage]; this will give u a actual image,
Otherwise the problem is with Context check for context is changing the image properties!!!
Could you explain that a little more? I did a little bit of research and all I could find on this was information on drawing an image with quartz, which I'm not doing. I'm simply loading a UIImage into a UIImageView, and whenever I do that with an image that originated from the iPhone camera, it ends up rotated -90.

I should probably point out that I'm currently storing the images in the database as blobs and reading/writing the image data as NSData. (I know this isn't the best way to do that, and I'll likely change it.) Could this be part of the problem? If I change my code to store the images as files instead, would that help?

By the way, thanks for all the help so far. I REALLY appreciate it!
Errornix is offline   Reply With Quote
Old 06-24-2009, 08:23 PM   #8 (permalink)
jsd
at this moment
 
Join Date: Mar 2009
Location: San Francisco, CA
Posts: 900
Default

See this blog post. It explains the problem and how to solve it.
jsd is offline   Reply With Quote
Old 06-25-2009, 09:23 PM   #9 (permalink)
Registered Member
 
Join Date: Jun 2009
Posts: 8
Default

Quote:
Originally Posted by jsd View Post
See this blog post. It explains the problem and how to solve it.
That worked!

Thanks again for all of the help!
Errornix is offline   Reply With Quote
Reply

Bookmarks

Tags
tableview, uiimage, uiimageview, 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: 354
22 members and 332 guests
ADY, Dani77, Duncan C, e2applets, HemiMG, Herbie, JasonR, keeshux, linkmx, macquitzon216, mer10, Monstertaco, piesia, prchn4christ, Promo Dispenser, Robiwan, sebasx, sly24, Touchmint, twerner, zulfishah
Most users ever online was 1,187, 10-11-2011 at 08:09 AM.
» Stats
Members: 158,881
Threads: 89,228
Posts: 380,760
Top Poster: BrianSlick (7,129)
Welcome to our newest member, macquitzon216
Powered by vBadvanced CMPS v3.1.0

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