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 09-14-2011, 09:59 AM   #1 (permalink)
Registered Member
 
Join Date: Jun 2010
Posts: 210
lukeirvin is on a distinguished road
Default How do I send an image from a UIViewController to a UITableViewCell

I have developed a filtering system using UIPicker's to get specific images.

I want to send this image back to the previous UIViewController and the image will be placed in a UITableViewCell.

What would be the best method to approach this?

NSUserDefaults? Or maybe save the image to NSData?

If you've done this before or found a tutorial that is close to this please share!

Thanks!
lukeirvin is offline   Reply With Quote
Old 09-14-2011, 10:25 AM   #2 (permalink)
Senior Member
iPhone Dev SDK Supporter
 
Join Date: Aug 2008
Location: Memphis, TN, USA
Age: 24
Posts: 3,983
smithdale87 is on a distinguished road
Send a message via AIM to smithdale87
Default

Is your "previous" view controller the one that the picker is shown in. Specifically, is that view controller the picker's delegate?
smithdale87 is offline   Reply With Quote
Old 09-14-2011, 10:49 AM   #3 (permalink)
Registered Member
 
Join Date: Jun 2010
Posts: 210
lukeirvin is on a distinguished road
Default

No.

The first UIViewController is a group table view. Each tableViewCell has a placeholder image.

When you tap a cell you will push to a new view that has the UIPicker (UIPickerDelegate and DataSource is in this UIViewController). Once the user filters down to the image they want they will tap a button to send them back to the previous View. I want the image they selected to now appear in that UITableViewCell.
lukeirvin is offline   Reply With Quote
Old 09-14-2011, 11:49 AM   #4 (permalink)
Senior Member
iPhone Dev SDK Supporter
 
Join Date: Aug 2008
Location: Memphis, TN, USA
Age: 24
Posts: 3,983
smithdale87 is on a distinguished road
Send a message via AIM to smithdale87
Default

There are a few ways to get the data back to the previous view controller (I'll call it viewController 1).

One way would be to:

- Add a property to your viewController2 that will be a reference to viewController1, when you create/show viewController2 from viewController1, be sure and set that property, probably just to "self"

- Add a method in your viewController1, called something like didSelectImage: (UIImage*)theImage. In your picker delegate method in viewController2 when the user picks an image, make a call to [self.viewController1 didSelectImage: theImage ].

- In the didSelectImage: method, you save the image in an array or somewhere that you can reference it by the indexPath of a tablecell. Then, you can call the reloadData method for the table cell.

- In your cellForRowAtIndexpath, you can lookup the new image that you just picked and put it in your cell.




Note: I realize there are some gaps in my little walkthrough. Hopefully, you can fill them in.


Edit:


Another way would be to make use of notifications.
- Setup viewController1 to listen for a specific notification, e.g. IDidSelectAnImageNotification
- Setup view controller2 to post the notification with the name above, and pass the selected along with it. This will happen in your picker delegate method.
- After you have the image in vc1, the rest will happen similar to above with the refresh the table view.

Last edited by smithdale87; 09-14-2011 at 11:52 AM.
smithdale87 is offline   Reply With Quote
Old 09-14-2011, 12:09 PM   #5 (permalink)
Registered Member
 
Join Date: Jun 2010
Posts: 210
lukeirvin is on a distinguished road
Default

This is what I am trying:

1st get the image based off filter
Code:
- (void)showImageFromFilter
{
    if ([brandTextField.text isEqualToString:@"Awake"] && [colorTextField.text isEqualToString:@"Purple"])    
    {        
        image = [UIImage imageNamed:@"awake_top_purple.png"];
        womenTopImageView = [[UIImageView alloc] initWithImage:image];
        
        womenTopImageView.contentMode = UIViewContentModeScaleAspectFit;
        
        womenTopImageView.frame = CGRectMake(60, 150, 190, 197);
        
        [self.view addSubview:womenTopImageView];
                
        [womenTopImageView release];
        [image release];
    }
}
2nd obtain imageview and set it to the image property

Code:
- (IBAction)imageSelectionTapped
{
    womenTopImageView.image = image;
    NSData * imageData;
    imageData = UIImagePNGRepresentation(image);
    [[NSUserDefaults standardUserDefaults] setObject:imageData forKey:[NSString stringWithFormat:@"%d",image]];
    
    [self dismissModalViewControllerAnimated:YES];
}
3rd display the image in a uitableviewcell
Code:
 if(indexPath.section == 1 && indexPath.row == 0)
        {
            if (cell.imageView.image == nil) 
            {
                cell.imageView.image = [UIImage imageNamed:@"placeholder.png"];
                cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
            }
            else
            {
                cell.imageView.image = womensTopImageView.image;
            }
}
The image is still not displaying in the UITableViewCell. I'm sure I'm not setting something correctly here. Can someone point out what I am missing.
lukeirvin is offline   Reply With Quote
Reply

Bookmarks

Tags
uiimage, uiimageview, uiview, uiviewcontroller

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: 404
16 members and 388 guests
7twenty7, Eclectic, eski, EvilElf, fiftysixty, HemiMG, iOS.Lover, JackReidy, jarv, Pudding, sacha1996, teebee74, tim0504, UMAD, VinceYuan, yuncarl28
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,672
Threads: 94,121
Posts: 402,905
Top Poster: BrianSlick (7,990)
Welcome to our newest member, yuncarl28
Powered by vBadvanced CMPS v3.1.0

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