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-13-2011, 11:07 AM   #1 (permalink)
Registered Member
 
Join Date: Jun 2010
Posts: 210
lukeirvin is on a distinguished road
Default Need help displaying an image based off UIPicker Selection

- (void)viewDidLoad
{
[super ViewDidLoad];

[brandTextField addTarget:self action:@selector(showImageFromFilter) forControlEvents:UIControlEventAllEvents];
}


- (void)showImageFromFilter
{
if (brandTextField.text == @"Awake")
{
NSString * imageString = @"awake_top_purple.png";

UIImage * womenTopImage = [[UIImage alloc] initWithContentsOfFile:imageString];

womenTopImageView.image = [[UIImageView alloc] initWithImage:womenTopImage];

womenTopImageView.contentMode = UIViewContentModeScaleAspectFit;
}
}

Here is the general idea of what I am doing.

I have 3 TextFields, each connected to a UIPicker. I have three sets of arrays with values. When I have specific values set I'd like for an image to display below the UITextFields.

This is what I am trying but doesn't seem to be working. Am I on the right track or can someone explain how I can get this to work.


Thanks
lukeirvin is offline   Reply With Quote
Old 09-13-2011, 11:48 AM   #2 (permalink)
Registered Member
 
Join Date: Jun 2010
Posts: 210
lukeirvin is on a distinguished road
Default

I changed the == to isEqualToString

Still not working though


Should I be calling this method in viewDidLoad or didSelectRow?
lukeirvin is offline   Reply With Quote
Old 09-13-2011, 02:23 PM   #3 (permalink)
Reading the Documentation
 
baja_yu's Avatar
 
Join Date: Sep 2010
Location: 45.255019,19.844908
Posts: 5,414
baja_yu has a spectacular aura about
Default

Please use [code] tags when posting source code.

Aside from the == problem when comparing objects, you are also leaking the image 'womenTopImage', and you're leaking the imageview you create on the next line. But more importantly, you are trying to assign an imageview object, to an image property of another imageview. Compiler should have at least given you a warning there, and you'd get a crash when that code is executed.
baja_yu is offline   Reply With Quote
Old 09-13-2011, 02:36 PM   #4 (permalink)
Registered Member
 
Join Date: Jun 2010
Posts: 210
lukeirvin is on a distinguished road
Default

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UIImageView scale]: unrecognized selector sent to instance 0x4b393c0'

I've been getting this warning a lot but can't find a solution for it.

I'm getting it at this line:

womenTopImageView.image = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"awake_top_purple.png"]];
lukeirvin is offline   Reply With Quote
Old 09-13-2011, 02:43 PM   #5 (permalink)
Reading the Documentation
 
baja_yu's Avatar
 
Join Date: Sep 2010
Location: 45.255019,19.844908
Posts: 5,414
baja_yu has a spectacular aura about
Default

Read the last two sentences of my post again.

For future reference, when you get a crash and ask for assistance, it helps others a lot that want to help you if you post the details of the crash up front.
baja_yu is offline   Reply With Quote
Old 09-13-2011, 02:52 PM   #6 (permalink)
Registered Member
 
Join Date: Jun 2010
Posts: 210
lukeirvin is on a distinguished road
Default

- (void)showImageFromFilter
{
if ([brandTextField.text isEqualToString:@"Awake"])
{
womenTopImageView.image = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"awake_top_purple.png"]];
womenTopImageView.contentMode = UIViewContentModeScaleAspectFit;
[womenTopImageView release];
}
}

This is what I am trying now. I can't see what I am over looking though with the image object.
lukeirvin is offline   Reply With Quote
Old 09-13-2011, 02:58 PM   #7 (permalink)
Reading the Documentation
 
baja_yu's Avatar
 
Join Date: Sep 2010
Location: 45.255019,19.844908
Posts: 5,414
baja_yu has a spectacular aura about
Default

Again, [code] tags, please!

Code:
womenTopImageView.image = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"awake_top_purple.png"]];
And you're still leaking the imageview object you allocated and never released.
baja_yu is offline   Reply With Quote
Old 09-13-2011, 03:06 PM   #8 (permalink)
Registered Member
 
Join Date: Jun 2010
Posts: 210
lukeirvin is on a distinguished road
Default

I thought I was releasing that though. I don't understand what needs to be released.
lukeirvin is offline   Reply With Quote
Old 09-13-2011, 03:21 PM   #9 (permalink)
Reading the Documentation
 
baja_yu's Avatar
 
Join Date: Sep 2010
Location: 45.255019,19.844908
Posts: 5,414
baja_yu has a spectacular aura about
Default

You need to read the Memory Management Programming Guide: Loading… In short everything you copy, alloc, retain or new, you must release. But do read the guide, and as many times as you need until you fully understand it. Concepts explained there are absolutely a must-know.

In your code you were releasing womenTopImageView, but that's even worse since you weren't setting it, but it's image property. UIImage is not the same as UIImageView. Instead of assigning an imageview to the image property, you need to assign a UIImage to it.
baja_yu is offline   Reply With Quote
Old 09-13-2011, 03:39 PM   #10 (permalink)
Registered Member
 
Join Date: Jun 2010
Posts: 210
lukeirvin is on a distinguished road
Default

Code:
if ([brandTextField.text isEqualToString:@"Awake"] && [colorTextField.text isEqualToString:@"Purple"])    
    {
        womenTopImageView.frame = CGRectMake(70, 150, 214, 253);
        
        image = [UIImage imageNamed:@"awake_top_purple.png"];
        womenTopImageView = [[UIImageView alloc] initWithImage:image];
        
        womenTopImageView.contentMode = UIViewContentModeScaleAspectFit;
        
        [self.view addSubview:womenTopImageView];
                
        [womenTopImageView release];
        [image release];
    }
I'm getting closer! The image displays now but it's showing up in the top left corner of the view. It's not placing the image in the UIViewController I have in the view. Just have to figure out how to position the image and it's good to go!

Thanks for the help!
lukeirvin is offline   Reply With Quote
Old 09-13-2011, 03:44 PM   #11 (permalink)
Reading the Documentation
 
baja_yu's Avatar
 
Join Date: Sep 2010
Location: 45.255019,19.844908
Posts: 5,414
baja_yu has a spectacular aura about
Default

You do it by setting the 'frame' property of the imageview.
baja_yu is offline   Reply With Quote
Reply

Bookmarks

Tags
display, ios, iphone, uiimage, uipicker

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: 411
15 members and 396 guests
7twenty7, Eclectic, eski, EvilElf, fiftysixty, HemiMG, iOS.Lover, JackReidy, jarv, 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:09 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0