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 03-12-2010, 04:46 AM   #1 (permalink)
Registered Member
 
Join Date: Mar 2010
Posts: 5
Default Get value of hidden for UIImageView??

Hi all

Run down:

I have a UIImageView and a button, I have the right outlets and actions set up to interact with them

withing my IBAction method for the button I want an if statement to determine the visablity of the UIImageView then change it to the opposite

something like this

If (myImage.hidden = YES)
{ myImage.hidden = NO;}
else
{ myImage.hidden = YES;}

I think my problem is when gettin the state of myImage as if I simply state

myImage.hidden = YES;

then it hides myImage.

Any suggestions, am I missing something?
To be honest I'm coming from a visual basic background so I could be trying to check the visiblity to completely wrong way!

Thanks for your help!

Sent from my iPhone
Toliver182 is offline   Reply With Quote
Old 03-12-2010, 05:01 AM   #2 (permalink)
iPhone SDK helper
 
Join Date: Feb 2010
Location: Austria, near Vienna
Posts: 169
Default

Quote:
Originally Posted by Toliver182 View Post
Hi all

Run down:

I have a UIImageView and a button, I have the right outlets and actions set up to interact with them

withing my IBAction method for the button I want an if statement to determine the visablity of the UIImageView then change it to the opposite

something like this

If (myImage.hidden = YES)
{ myImage.hidden = NO;}
else
{ myImage.hidden = YES;}

I think my problem is when gettin the state of myImage as if I simply state

myImage.hidden = YES;

then it hides myImage.

Any suggestions, am I missing something?
To be honest I'm coming from a visual basic background so I could be trying to check the visiblity to completely wrong way!

Thanks for your help!

Sent from my iPhone
You are setting the value already inside of your if-clause! You need to use double equal-signs to check if it is hidden or not, otherwise you are setting it!
myImage.hidden==YES is not the same as myImage.hidden=YES.

Change your code to the following and it should work:
Code:
if(myImage.hidden){
myImage.hidden=NO;
}else{
myImage.hidden=YES;
}
chaoz1337 is offline   Reply With Quote
Old 03-12-2010, 05:05 AM   #3 (permalink)
Registered Member
 
Join Date: Mar 2010
Posts: 63
Default

You can also use a single line
Code:
 myImage.hidden=!myImage.hidden;
firearasi is offline   Reply With Quote
Old 03-12-2010, 05:06 AM   #4 (permalink)
Registered Member
 
Join Date: Mar 2010
Posts: 5
Default

Awesome thanks for the quick reply guys!
Toliver182 is offline   Reply With Quote
Old 03-12-2010, 05:11 AM   #5 (permalink)
iPhone SDK helper
 
Join Date: Feb 2010
Location: Austria, near Vienna
Posts: 169
Default

It's also working with firearasi's solution. I just wrote it out for better understanding. But it does the same.
chaoz1337 is offline   Reply With Quote
Old 03-12-2010, 06:59 AM   #6 (permalink)
Cocoa Junkie
 
Duncan C's Avatar
 
Join Date: Dec 2008
Location: Northern Virginia
Posts: 4,814
Default if (a = b) strikes again!

Quote:
Originally Posted by chaoz1337 View Post
You are setting the value already inside of your if-clause! You need to use double equal-signs to check if it is hidden or not, otherwise you are setting it!
myImage.hidden==YES is not the same as myImage.hidden=YES.

Change your code to the following and it should work:
Code:
if(myImage.hidden){
myImage.hidden=NO;
}else{
myImage.hidden=YES;
}
Personally, I think this is one of the stupidest things about C. Anybody who uses the if (a = b) syntax should be shot for being too cute.

Show me a C programmer who has not wasted many, many hours in his/her career hunting down bugs, only to find that he or she accidentally used an "=" (assignment) instead of an "==" comparison, and I'll show you a programmer who hasn't been programming in C for very long.

This usage should be flagged with a warning by the compiler.


Duncan
Duncan C is offline   Reply With Quote
Reply

Bookmarks

Tags
hidden, if statement, uiimageview

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: 320
20 members and 300 guests
@sandris, ADY, dacapo, Dani77, djohnson, dre, HDshot, HemiMG, JasonR, MarkC, mer10, nibeck, prchn4christ, ryandb2, spiderguy84, timle8n1, tomtom100, vogueestylee, vvenkatachallam
Most users ever online was 1,187, 10-11-2011 at 08:09 AM.
» Stats
Members: 158,883
Threads: 89,229
Posts: 380,763
Top Poster: BrianSlick (7,129)
Welcome to our newest member, vvenkatachallam
Powered by vBadvanced CMPS v3.1.0

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