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

liptonlover

macrumors 6502a
Original poster
Mar 13, 2008
989
0
Here's the code...

Code:
- (void)sendVariable:(float)variable toOutlet:(id)outlet {
	[outlet setText:variable];
}

Here's the error.
error: incompatible type for argument 1 of 'setText:'

The text property in UILabel accepts NSStrings only but I need it to display float values. I looked under NSString but couldn't find anything such as 'stringFromDouble' so I don't know what to do.

Also... I got this warning.
Code:
warning: conflicting types for '-(void)sendVariable:(float)variable toOutlet:(id)outlet'

I don't understand what this warning means. Can anyone help?
Thanks in advance, Nate
 

liptonlover

macrumors 6502a
Original poster
Mar 13, 2008
989
0
Ok, here's the code now.
Code:
- (void)sendVariable:(float)variable toOutlet:(id)outlet {
	[string initWithFormat:@"%f"];
	[string setValue:variable];
	[outlet setText:string];
	[string release];
}
I have one more problem. Now that I've formatted the NSString instance, I don't know how to give it a value. It doesn't have a setValue: property or method, nor does it have a setText: one. Sorry if I'm missing something painfully obvious, it wouldn't be the first time.
 

jnic

macrumors 6502a
Oct 24, 2008
567
0
Cambridge
Ok, here's the code now.
Code:
- (void)sendVariable:(float)variable toOutlet:(id)outlet {
	[string initWithFormat:@"%f"];
	[string setValue:variable];
	[outlet setText:string];
	[string release];
}
I have one more problem. Now that I've formatted the NSString instance, I don't know how to give it a value. It doesn't have a setValue: property or method, nor does it have a setText: one. Sorry if I'm missing something painfully obvious, it wouldn't be the first time.

http://developer.apple.com/DOCUMENTATION/Cocoa/Conceptual/Strings/Articles/FormatStrings.html

Code:
- (void)sendVariable:(float)variable toOutlet:(id)outlet {
	[outlet setText:[NSString stringWithFormat:@"%f", variable]];
}
 

liptonlover

macrumors 6502a
Original poster
Mar 13, 2008
989
0
Thanks, I didn't know stringWithFormat could then accept a variable as a second argument.
Thanks, Nate
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.