Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

bguy

macrumors newbie
Original poster
May 30, 2009
28
0
In a program I am trying to make, I have a reset button, which I want to have it reset all the variables. I have made it work in that respect, but then I implemented images. I understand how to assign the images, but I want to have the program reset the image views as well so it shows up blankly. How can you do this? I tried setting them to NULL and setting them to an undisturbed image, but neither worked.
 
[imageView setImage:nil]; should work. Can you post some code if it's not working? Are your IBOutlets connected properly?
 
[imageView setImage:nil];
That is what I was looking for. I know the images work because I have them setting and changing, just not eracing. COuld someone explain to be the difference between nil and NULL?
 
yeah


objective C uses nil instead of NULL, well i guess you can use any C but in cocoa apps I think nil is what you need to use... i do for iphone sdk.
 
NULL is basically ASCII character 00.

NULL can be for different things, for instance a memory address of all zeros.
An empty C string is basically 00, and you end C-strings with a NUL character which is \0 if entered by hand.

nil is an object. nil is basically an empty object pointer, but is in fact an object.

Instance variables that are objects are initialized to nil.
You can send messages to nil and I believe they are ignored.

You can check to see if an object is nil like
if ( someStringObject == nil ) { someObject = @"yes"; }

but not!!!
if ( someStringObject == NULL ) { blah; }
(since even an uninitialized ivar does not point to empty memory)
 
NULL is basically ASCII character 00.

NULL can be for different things, for instance a memory address of all zeros.
An empty C string is basically 00, and you end C-strings with a NUL character which is \0 if entered by hand.

nil is an object. nil is basically an empty object pointer, but is in fact an object.

Instance variables that are objects are initialized to nil.
You can send messages to nil and I believe they are ignored.

You can check to see if an object is nil like
if ( someStringObject == nil ) { someObject = @"yes"; }

but not!!!
if ( someStringObject == NULL ) { blah; }
(since even an uninitialized ivar does not point to empty memory)

Just to clarify: an object pointer that == nil will also == NULL, because nil and NULL are the same. They're cast differently but they're both zero. When an NSObject is first alloc'd (before any of its ivars are init'd or set), its ivars are all zeroed out. All of its ivar object pointers will equal nil. They will also all equal NULL, if compared. Uninitialized ivars point to zero (nil, NULL).
 
Just to clarify: an object pointer that == nil will also == NULL, because nil and NULL are the same. They're cast differently but they're both zero. When an NSObject is first alloc'd (before any of its ivars are init'd or set), its ivars are all zeroed out. All of its ivar object pointers will equal nil. They will also all equal NULL, if compared. Uninitialized ivars point to zero (nil, NULL).
That would explain why NULL was working for me until that point.
 
Just to clarify: an object pointer that == nil will also == NULL, because nil and NULL are the same. They're cast differently but they're both zero. When an NSObject is first alloc'd (before any of its ivars are init'd or set), its ivars are all zeroed out. All of its ivar object pointers will equal nil. They will also all equal NULL, if compared. Uninitialized ivars point to zero (nil, NULL).

This may be true, I've never tried.

However you cannot pass messages to NULL.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.