Re: Objective C array
Re: Objective C array
- Subject: Re: Objective C array
- From: Sherm Pendley <email@hidden>
- Date: Fri, 31 May 2002 16:56:36 -0400
On Friday, May 31, 2002, at 04:29 PM, Eric Conrad wrote:
Hello,
I am new to Objective-C I tried getting help on this through the C
gurus on IRC, but they couldn't help either. What I want to do is read
an array with a simple for loop. Basically I'm making a simple GPA
calculating program. Here is my code:
- (IBAction)calculate:(id)sender
{
float classCredits[10];
float classGrades[10];
float totalCredits, totalGrades, gpaFinal;
int i;
for(i=0; i<10; i++)
{
classCredits[i] = [classCredit? floatValue]; <--------
classGrades[i] = [classGrade? floatValue]; <--------
}
One thing that comes to mind is tags. You can assign a unique integer
tag value to each classCredit? field in IB, and use NSView's
viewWithTag: method to retrieve a reference to the correct one each time
through the loop. For example, assuming that "classWindow" is an outlet
connected to the window containing the fields:
- (IBAction)calculate:(id)sender
{
float classCredits[10];
float classGrades[10];
float totalCredits, totalGrades, gpaFinal;
int i;
NSView *classTopView;
classTopView = [classWindow contentView];
for(i=0; i<10; i++)
{
classCredits[i] = [[classTopView viewWithTag: 100+i] floatValue];
classGrades[i] = [[classTopView viewWithTag: 200+i] floatValue];
}
}
The above also assumes that tags 100-109 have been assigned to
classCredit? fields, and 200-209 to classGrade? fields.
I typed this directly into email, without compiling it, so there may be
typos.
Hope this helps!
sherm--
Never put off until tomorrow what you can do today. There might be a law
against it by that time.
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.