Objective C images

Discussion in 'Mac Programming' started by bguy, Jun 19, 2009.

  1. macrumors newbie

    Joined:
    May 30, 2009
    Messages:
    28
    #1
    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.
     
  2. Moderator emeritus

    kainjow

    Joined:
    Jun 15, 2000
    Messages:
    7,743
    #2
    [imageView setImage:nil]; should work. Can you post some code if it's not working? Are your IBOutlets connected properly?
     
  3. macrumors newbie

    Joined:
    May 30, 2009
    Messages:
    28
    #3
    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?
     
  4. macrumors 65816

    Joined:
    May 21, 2009
    Messages:
    1,112
    Location:
    Chicago
    #4
    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.
     
  5. macrumors 68030

    jared_kipe

    Joined:
    Dec 8, 2003
    Messages:
    2,963
    Location:
    Seattle
    #5
    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)
     
  6. macrumors newbie

    Joined:
    Dec 8, 2008
    Messages:
    26
    Location:
    Oregon, USA
    #6
    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).
     
  7. macrumors newbie

    Joined:
    May 30, 2009
    Messages:
    28
    #7
    That would explain why NULL was working for me until that point.
     
  8. macrumors 68030

    jared_kipe

    Joined:
    Dec 8, 2003
    Messages:
    2,963
    Location:
    Seattle
    #8
    This may be true, I've never tried.

    However you cannot pass messages to NULL.
     

Share This Page