Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > Beginner Cocoa Help

Beginner Cocoa Help
Thread Tools
Fresh-Faced Recruit
Join Date: Jul 2006
Location: Canada
Status: Offline
Reply With Quote
Apr 30, 2006, 12:39 PM
 
Well after following Apple's Currency Converter tutorial for Cocoa, I decided to make my own app. I use the same basic layout, except modified. Basically my program converts measures and beats into minutes and seconds. It works so far except I have one problem, when it displays seconds if it is less than 10 it just says the number like 7 instead of 07 so I was wondering how would I make it always have 2 digits? Here is the source so far:
float measures, beats, MtoB, BPM, BPS, totalBeats, seconds, minutes;
measures = [MeasuresField floatValue];
beats = [BeatsField floatValue];
BPM = [BPMField floatValue];
measures = measures - 1; /*garageband uses a base of 1, so technically when it has a 2 in the measures column, it is actually only 1 full measure*/
MtoB = measures * 4; /*converts the measures to beats*/
beats = beats - 1; /*garageband also uses a base of 1 in the beats column*/
totalBeats = MtoB + beats;
BPS = BPM / 60;
seconds = totalBeats / BPS;
minutes = seconds / 60;
minutes = (int)minutes;
seconds = seconds - (minutes * 60);
[SecondsField setFloatValue:seconds];
[MinutesField setFloatValue:minutes];
     
Mac Elite
Join Date: Aug 2001
Status: Offline
Reply With Quote
Apr 30, 2006, 02:02 PM
 
     
Professional Poster
Join Date: Dec 2000
Location: Chicago, Illinois
Status: Offline
Reply With Quote
Apr 30, 2006, 09:05 PM
 
I think a format of @"%02d" will do the trick.
     
Clinically Insane
Join Date: Oct 2001
Location: San Diego, CA, USA
Status: Offline
Reply With Quote
Apr 30, 2006, 09:14 PM
 
You could also just hook the field up to an NSNumberFormatter in the nib.
Chuck
___
"Instead of either 'multi-talented' or 'multitalented' use 'bisexual'."
     
geofaw  (op)
Fresh-Faced Recruit
Join Date: Jul 2006
Location: Canada
Status: Offline
Reply With Quote
May 1, 2006, 08:24 PM
 
Originally Posted by Chuckit
You could also just hook the field up to an NSNumberFormatter in the nib.
Thanks for the help, but I found this method the best. All i had to do was drag the NSNumberFormatter onto the NSTextField and then change the settings in the Formatter panel. It worked great and was really easy for a beginner like me.
     
   
Thread Tools
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Top
Privacy Policy
All times are GMT -5. The time now is 10:47 PM.
All contents of these forums © 1995-2011 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.7 © 2000-2011, Jelsoft Enterprises Ltd., Content Relevant URLs by vBSEO 3.3.2