Using 'if' on an NSArray element?

Discussion in 'iOS Programming' started by bmcgonag, Oct 22, 2011.

  1. bmcgonag, Oct 22, 2011
    Last edited: Oct 24, 2011

    bmcgonag macrumors 65816

    bmcgonag

    Joined:
    Mar 20, 2007
    Location:
    Texas
    #1
    Edits are in Red below
    I'm populating two text fields using a UIPickerView with two columns of data.

    I want to ensure that the first entry for each column is not still selected when the action button is touched.

    So imagine a two column UIPicker View, and as the index 0 entry I have 'Choose' on each column.

    I know i need to do an if / else if statement to check this, but have no idea how to refer to those elements.

    Should I refer to the column index at 0 somehow, or can I check the label itself to see if it still has the default title I set in the attributes when the program is first launched?

    I already have the Picker View getting the selected element into the text boxes, but now I need to use those selections when the button is pressed.

    Any help is greatly appreciated.
     
  2. bmcgonag thread starter macrumors 65816

    bmcgonag

    Joined:
    Mar 20, 2007
    Location:
    Texas
    #2
    Okay, a bit of an update.

    I've done this...

    Code:
    if ([@"Time" isEqualToString:timeAmt.text]) {
     missingAlert ....
    } else if ([@"Unit" isEqualtToString:timeMinorSec.text]){
        missingAlert ....
        }
    
    I goe no warnings or errors, and it builds successfully, but still when I click the button, nothing comes up even though my criteria are met in both cases.

    Any help?
     
  3. chown33 macrumors 604

    Joined:
    Aug 9, 2009
    Location:
    Brobdingnag
    #3
    That's not your real code. The red-hilited method name is spelled wrong.

    Please copy and paste real code. Don't edit it or paraphrase it.

    Please post complete code for the method.

    Please post the @interface of the class, or whatever else is necessary to know what the type of the variables is (e.g. timeAmt & timeMinorSec types).

    Please post the UIPickerView code.

    What have you done to debug this? Do you have an NSLog in the action method of the button? If so, does it produce the expected output at the expected time?

    If you NSLog the actual text properties of timeAmt & timeMinorSec, exactly what is output?

    Have you confirmed that the variables timeAmt & timeMinorSec are non-null? Is this confirmation in the action method of the button?
     
  4. ArtOfWarfare macrumors G3

    ArtOfWarfare

    Joined:
    Nov 26, 2007
    #4
    I would think that this wouldn't be the best method of making the user pick something valid...

    If you refer to Apple's official Clock app and then go over to the Timer tab, the UISpinnerView indicates what each column is by having the units floating by each number. There are no header elements for the user to mistakenly pick.

    So it seems to me you shouldn't have any improper things that can be selected.
     
  5. bmcgonag thread starter macrumors 65816

    bmcgonag

    Joined:
    Mar 20, 2007
    Location:
    Texas
    #5
    I actually had not added an NSLog entry, so I did that, and I get the NSLog output for my first condition, so I apparently have something wrong in trying to generate my Alert.

    I will work on that for now, but your advice helped.

    I didn't paste the code, because I'm not home now, so I was doing it from memory. I'm a bit of a newbie so I'm surprised I remembered as much as I did, even with the typo.

    ----------

    Thanks for pointing that out, I hadn't even noticed that they do that.

    I have added a 0 for time, and a blank for units. My setup won't quite work like Apple's does for my purposes, but your suggestion did lead me to a better solution.

    As for the 'if' test, I am testing instead against the value in the UILabel where the time and units get placed when a selection is made.

    Now I just need to get my Alert working properly, and I can add from there.

    Thanks to both posters who gave me answers and hints.
     
  6. chown33 macrumors 604

    Joined:
    Aug 9, 2009
    Location:
    Brobdingnag
    #6
    For future reference, it's usually better for everyone if you post actual code and the actual output, rather than just summarizing or describing it. For example:
    This is the action method code that logs important values:
    Code:
    paste complete code here, in CODE tags.
    
    If there's something non-obvious about the code, describe it.

    Here is the output when the button is clicked (or whatever the action is):
    Code:
    paste actual output here, in CODE tags.
    
    The reason for this is simple: we can't debug descriptions of code. Nor can we see clues about possible bugs in the descriptions of output. We need to see the actual code and the actual output.
     
  7. bmcgonag thread starter macrumors 65816

    bmcgonag

    Joined:
    Mar 20, 2007
    Location:
    Texas
    #7
    I understand completely.

    I'm just excited to get something working on the app, and couldn't wait until I got home to post more info.

    I will post the actual code with more questions tonight. I want to try and rundown my next issue on my own first.

    Thanks again to everyone for your help.
     

Share This Page