Thursday, May 6, 2010

IPad Math: Fixing the code, and advancing through paths.

The next step is to make a progressive ability to represent the states of the items.  I've also added some highlighting ability.


  1. Modify the MathProblem class to have problemNumber property for which particular index of problems it is.
  2. Modify MathDrillViewController so that it has a currentProblem integer value, as well as an array of problems.
  3. Add a set problem method that sets the current problem

In this code segment the setProblemNumber will find the previous problem and reset it's alpha to 0.5.  It then set the current problem and changes the alpha to 1.  Note that I need to refractor this code a bit.
- (void) setProblemNumber:(int) problemNumber
{
NSLog(@"Choosing problem %d",problemNumber);
if ((currentProblem>=0) && (currentProblem<=[currentProblems count]))
{
MathProblem *oldProblem=(MathProblem*)[currentProblems objectAtIndex:currentProblem];

oldProblem.view.alpha=0.5;
}
currentProblem=problemNumber;
MathProblem *problem=(MathProblem*)[currentProblems objectAtIndex:currentProblem];
problem.view.alpha=1;
}


In this code segment I modified the math problem creation to load an array, and set the alpha to 0.5
- (void)viewDidLoad {
    [super viewDidLoad];
int width=self.view.frame.size.width/6;
int height=(self.view.frame.size.height-100)/5;

currentProblems=[[NSMutableArray alloc]init];
for (int row=0;row<5;row++)
{
for (int column=0;column<6;column++)
{
MathProblem *problem=[[MathProblem alloc] initWithMax:10];
problem.problemNumber=row*6+column;
problem.view.alpha=0.5;
[self.currentProblems addObject:problem];

problem.view.frame=CGRectMake(column*width, height*row, width, height);
problem.controller=self;
// problem.view.frame=CGRectMake(40, 40, 100, 100);
[self.view addSubview:problem.view];
}
}

int buttonWidth=resultChoices.frame.size.width/10;
int buttonHeight=resultChoices.frame.size.height;
resultChoices.userInteractionEnabled=true;
self.view.userInteractionEnabled=true;
 
for (int i=0;i<10;i++)
{
UIButton *button=[[[UIButton alloc]init] retain];
button.tag=i;
button.frame=CGRectMake(i*buttonWidth,buttonHeight+resultChoices.frame.origin.y,buttonWidth,buttonHeight);
button.backgroundColor=[UIColor redColor];
button.userInteractionEnabled=true;
[button setTitle:[NSString stringWithFormat:@"%d",i] forState:UIControlStateNormal];
[button addTarget:self action:@selector(buttonChosen:) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:button];
}
}


In this code segment I change the behavior of the select a number to increment to the next problem.



- (IBAction) buttonChosen:(id)sender
{
UIButton *button=(UIButton*) sender;
int choice=button.tag;
if ((currentProblem>=0) && (currentProblem<= [currentProblems count]))
{
MathProblem *problem=(MathProblem*)[currentProblems objectAtIndex:currentProblem];

[problem setChoice:choice];
NSLog(@"setting choice to %d",choice);

[self setProblemNumber:(currentProblem+1)%([currentProblems count])];
}
}

2 comments:

  1. I appreciate the information. iphone development with iphone
    developers
    is really grooming these days as demand for business and entertainment application is increasing.

    ReplyDelete
  2. Thanks for sharing this information. We also have good experience and knowledge in iPhone App Development

    ReplyDelete