View Full Version : Array display help
gizabo
Apr 22, 2009, 07:42 PM
Hey, I want to display one object in my array. How can I do this? Here is the code I tried using
[testLabel setStringValue:@"%@", myList(0)];
Thanks in advance
aaronw1986
Apr 22, 2009, 07:58 PM
Hey, I want to display one object in my array. How can I do this? Here is the code I tried using
[testLabel setStringValue:@"%@", myList(0)];
Thanks in advance
What language?
gnasher729
Apr 22, 2009, 08:03 PM
Hey, I want to display one object in my array. How can I do this? Here is the code I tried using
[testLabel setStringValue:@"%@", myList(0)];
Thanks in advance
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:
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)?
lee1210
Apr 22, 2009, 09:47 PM
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/DOCUMENTATION/Cocoa/Reference/Foundation/Classes/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/DOCUMENTATION/Cocoa/Reference/ApplicationKit/Classes/NSControl_Class/Reference/Reference.html#//apple_ref/occ/instm/NSControl/setStringValue:
This should help you figure out what sort of argument should be passed to this method.
-Lee
vBulletin® v3.8.6, Copyright ©2000-2012, Jelsoft Enterprises Ltd.