Okay, seriously. Help. Please. Basic.

Discussion in 'iOS Development' started by cocotutch, Dec 12, 2009.

Thread Status:
Not open for further replies.
  1. cocotutch

    cocotutch Community Development Team Staff Member

    Joined:
    Oct 6, 2008
    Messages:
    1,285
    Likes Received:
    117
    Device:
    5G iPod touch
    Okay,

    I'm adding a feature to my app that (WITH-HELD) and I want to have a UIImageView show an image that conforms to a UILabel's ".text" property.

    For example.

    I have 2 Labels,
    Pressing One Button will change the 320x480 Image behind EVERYTHING in the UIView to a green or red image (Please do not say set the Color Property) depending on whether the answer is correct or incorrect respectively.
    But it won't work. I got it working once with:

    [OBJC]if (answerLabel.text = @"4567") {
    backdrop_animated.image = [UIImage imageNamed

    Please Register or Log in to view images

    "GreenCorrect.png"];
    }
    else {
    if (answerLabel.text = @"3456") {
    backdrop_animated.image = [UIImage imageNamed

    Please Register or Log in to view images

    "RedWrong.png"];
    }
    else {
    backdrop_animated.image = [UIImage imageNamed

    Please Register or Log in to view images

    ""];
    }[/OBJC]

    I found a tip somewhere that you are meant to use "==" in the If statements. This resulted in NOTHING appearing on the backdrop no matter what. Is there something I am doing wrong? Please Help!

    This resulted in nothing:

    [OBJC]if (answerLabel.text == @"4567") {
    backdrop_animated.image = [UIImage imageNamed

    Please Register or Log in to view images

    "GreenCorrect.png"];
    }
    else {
    backdrop_animated.image = [UIImage imageNamed

    Please Register or Log in to view images

    ""];
    }
    if (answerLabel.text == @"3456") {
    backdrop_animated.image = [UIImage imageNamed

    Please Register or Log in to view images

    "RedWrong.png"];
    }
    else {
    backdrop_animated.image = [UIImage imageNamed

    Please Register or Log in to view images

    ""];
    }[/OBJC]

    What the Heck? This should be working, i'm really getting stressed over this! Please assist me

    Please Register or Log in to view images



    cocotutch
  2. SkylarEC

    SkylarEC Super Moderator Emeritus Staff Member

    Joined:
    Sep 19, 2007
    Messages:
    6,642
    Likes Received:
    129
    = is assignment. You're literally setting the string to the new value, which should always be true.
    == is the equality operator. The majority of the time, you can use with most variables. It can not be used to compare objects. The result should always be false.

    Use this instead:
    [someNSString isEqualToString:someOtherNSString]

    Also, your code has no failsafe for a nil string.
  3. cocotutch

    cocotutch Community Development Team Staff Member

    Joined:
    Oct 6, 2008
    Messages:
    1,285
    Likes Received:
    117
    Device:
    5G iPod touch
    How could I go about making a Failsafe? I tried but it results in the Empty screen again.......

    cocotutch
  4. lauNchD

    lauNchD Well-Known Member

    Joined:
    Jan 27, 2008
    Messages:
    1,844
    Likes Received:
    261
    Device:
    iPhone 5 (Black)
    [OBJC]NSString *userEntry = answerLabel.text; // Store answer in local variable to avoid redundant Obj-C messages

    if ([userEntry isEqualToString: @"4567"])
    backdrop_animated.image = [UIImage imageNamed

    Please Register or Log in to view images

    "GreenCorrect.png"];
    else if ([userEntry isEqualToString: @"3456"])
    backdrop_animated.image = [UIImage imageNamed

    Please Register or Log in to view images

    "RedWrong.png"];
    else
    backdrop_animated.image = nil; // Why imageNamed: and an empty string? (Wastes CPU cycles)[/OBJC]

    If you don't understand the most basic fundaments, you really shouldn't be putting apps into the store.
    This isn't a personal insult; I'm sorry if I'm offending you
  5. cocotutch

    cocotutch Community Development Team Staff Member

    Joined:
    Oct 6, 2008
    Messages:
    1,285
    Likes Received:
    117
    Device:
    5G iPod touch
    Hey hey now, I'v never worked with this stuff before now

    Please Register or Log in to view images

    I have never added something like this to any of my apps before so that's most probably why I sucked at it.

    I understand most of the basic fundamentals of Objective-C Programming, there is just some stuff that i'm not "fluent" in yet (for example, writing any sort of Game).
  6. Steaps

    Steaps New Member

    Joined:
    Oct 24, 2007
    Messages:
    5,074
    Likes Received:
    41
    Device:
    iPod touch
    This is the BASIC's of any programming language. I'm with lauNchD on this one.
  7. bddckr

    bddckr Active Member

    Joined:
    Dec 2, 2007
    Messages:
    1,434
    Likes Received:
    18
    Device:
    iPhone 4 (Black)
    When did if-else become a member of that game-programming stuff?

    Really, seems like someone needs to learn the basic stuff first.
  8. BlackSoil

    BlackSoil New Member

    Joined:
    Dec 30, 2008
    Messages:
    3
    Likes Received:
    0
    Device:
    2G iPod touch
    you need to learn more simple language.. you haven't even understood the if-else logic..
  9. cocotutch

    cocotutch Community Development Team Staff Member

    Joined:
    Oct 6, 2008
    Messages:
    1,285
    Likes Received:
    117
    Device:
    5G iPod touch
    Okay, i'm sick of all the personal slander here.

    I DO understand the basic "if-else" logic as I have been using it since the iPhone SDK's inception with 2.0. I also spent a good 2 years learning AppleScript to introduce myself to the world of Programming. I moved to Objective-C with iPhone SDK FW 2.0.

    And I know that the "if-else" isn't usually, or can be involved in Game Programming. My comment DID mean the following "I understand most Basics, that's what I have been doing. I don't know much of the terribly advanced stuff in the iPhone SDK, but i'm getting there."

    You see? I thought a nice succinct post would go down well here, but obviously not. Learn your grammar and learn your vocabulary. It MAY help you, but you're probably beyond repair already.
  10. Steaps

    Steaps New Member

    Joined:
    Oct 24, 2007
    Messages:
    5,074
    Likes Received:
    41
    Device:
    iPod touch
    Learn your grammar? No, thanks. This sentence makes no sense.
    "And I know that the "if-else" isn't usually, or can be involved in Game Programming."
Thread Status:
Not open for further replies.

Share This Page