PDA

View Full Version : Objective C images




bguy
Jun 19, 2009, 10:05 AM
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.



kainjow
Jun 19, 2009, 11:51 AM
[imageView setImage:nil]; should work. Can you post some code if it's not working? Are your IBOutlets connected properly?

bguy
Jun 19, 2009, 01:31 PM
[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?

tempusfugit
Jun 19, 2009, 02:18 PM
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.

jared_kipe
Jun 19, 2009, 03:23 PM
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)

BravoBug
Jun 20, 2009, 06:50 AM
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).

bguy
Jun 20, 2009, 09:05 AM
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.

jared_kipe
Jun 20, 2009, 12:21 PM
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.