Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

gizabo

macrumors regular
Original poster
Jul 20, 2008
124
0
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
 
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

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)?
 
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
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.