Array display help

Discussion in 'Mac Programming' started by gizabo, Apr 22, 2009.

  1. gizabo macrumors regular

    Joined:
    Jul 20, 2008
    #1
    Hey, I want to display one object in my array. How can I do this? Here is the code I tried using
    Code:
    	[testLabel setStringValue:@"%@", myList(0)];
    
    Thanks in advance
     
  2. aaronw1986 macrumors 68030

    Joined:
    Oct 31, 2006
    #2
    What language?
     
  3. gnasher729 macrumors P6

    gnasher729

    Joined:
    Nov 25, 2005
    #3
    Get a C book. Lookup what a "comma-expression" is. Then ask yourself why you are passing a comma expression to setStringValue. Then fill in the missing bits in this:

    Code:
    	NSString* theFormattedString = <what goes here>;
    	[testLabel setStringValue: <and what goes here>];
    
    And after that, how do you write this in one line (if that is what you prefer)?
     
  4. lee1210 macrumors 68040

    lee1210

    Joined:
    Jan 10, 2005
    Location:
    Dallas, TX
    #4
    Some other things to consider... what is the type of myList? What does the expression myList(0) return? Is myList a C function? If not, the syntax is not correct. Is it an NS(Mutable)Array? If so, you need to pass a message, not use a C construct like x() or x[].

    Some references:
    C operators
    http://www.cs.mun.ca/~michael/c/op.html
    This table includes [], (), and ,. See which, if any, of these you need in this case. () is also used when invoking a function.

    NSString
    http://developer.apple.com/DOCUMENT...lasses/NSString_Class/Reference/NSString.html
    This should help you fill in one of the blanks in gnasher729's example, and would also help in achieving this in a single line.

    NSControl's setStringValue:
    http://developer.apple.com/DOCUMENT...apple_ref/occ/instm/NSControl/setStringValue:
    This should help you figure out what sort of argument should be passed to this method.

    -Lee
     

Share This Page