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

macindev

macrumors newbie
Original poster
Jul 6, 2009
14
0
Seattle, Washington, USA
What I am trying to do is use the batteryLevel method to set it's float value to the float value of a ProgressView. But unfortunatley, I keep running into errors.
I get one that says "Expected expression before 'float'.
And one that says "Expected ':' before ']' token.

Code:
- ([COLOR="magenta"]void[/COLOR])setChargeProgBar:([COLOR="magenta"]id[/COLOR])sender{
	[[COLOR="teal"]chargeProgBar[/COLOR] floatValue:[[COLOR="magenta"]float[/COLOR] [COLOR="navy"]batteryLevel[/COLOR]]];
}

This will be my first iPhone app... if it ever works...
Any help would be great.
 
floatValue: isn't a valid method (unless you defined it somewhere...). What is chargeProgBar?
 
Yes, setChargeProgBar: is the outlet to my UIProgressView. I checked out the API Documentation, but I still don't understand how I tell the progress bar to set it's float value to that of the batteryLevel's float value.
Can anyone help me please?
Also, I should add that I'm fairly new at C/ObjC.
 
If you don't know how to use Objective-C properties, I suggest reading up on them.

To do what you want, do:
Code:
chargeProgBar.progress = someFloatValue;
 
I know I'm starting to get annoying, but I thought I had figured out programming in Xcode, but I guess not.
I just don't get why I'm always having so many errors with floating-point...

Sorry if the code looks like it came from a 3 year-old kid...:(

Here's the code/errors:
Code:
- (void)showDeviceModel:(id)sender{
	[deviceModel setString: (NSString *)model];
}

- (BOOL)isBatteryMonitoringEnabled:(id)sender{
	return YES;

}
- (void)setChargePercentIndicator:(id)sender{
	[chargePercentIndicator setString:[[@"Charge: " stringByAppendingString:[float batteryLevel]] stringByAppendingString:@"%"]];
[COLOR="red"]Error: expected expression before 'float'.[/COLOR]
}
	
- (id)initWithProgressViewStyle:(UIProgressViewStyle)UIProgressViewStyleDefault{
}

- (void)setChargeProgBar:(id)sender{
	[[chargeProgBar progress] (float)batteryLevel];
[COLOR="red"]Error: expected expression before 'float'.[/COLOR]
}

If I try to take out 'float', then it won't recognize batteryLevel.
I've attached a screenshot of what it should look like in the end.
 

Attachments

  • photo.jpg
    photo.jpg
    14.3 KB · Views: 93
Sorry about that, I was just stuck on figuring what the heck it all was. I've done more with Mac OS programming rather than iPhone OS. And to think I thought it would be exactly the same?

I'm still trying to figure out how to convert my random assortment of methods and syntax into a neat implementation.

Thanks for all of the help!
 
I've done more with Mac OS programming rather than iPhone OS. And to think I thought it would be exactly the same?
Well, if your Mac OS programming was using Objective-C, they are very, very similar. Much more alike than different. Granted, not exactly the same. :)
 
Sorry about that, I was just stuck on figuring what the heck it all was. I've done more with Mac OS programming rather than iPhone OS. And to think I thought it would be exactly the same?

Not to be rude, but most of your errors show a lack of understanding of how Objective-C programming works and have little if anything to do with the iPhone.
 
I'm pretty sure float is a C keyword and can't be a variable name so anything like:

Code:
[float methodName];

is going to (and will always have on OSX) cause issues. I suggest you go back and learn very basic C.
 
Short answer: read up on Obj-C 2.0 properties in the Obj-C 2.0 programming guide.

Long answer: read a book on iPhone development. That's the way to learn.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.