問題は、条件が満たされた場合に、ユーザーが配列に配置したすべてのエントリデータを基本的に消去する方法が必要なことです。Objective-CとiOSのプログラミングは初めてですが、解決策はviewDidLoadメソッドを呼び出すことである可能性があると考えていたため、配列の値をデフォルトにリセットしてアプリケーションを仮想的に更新します。これを行う他の論理的な方法がある場合は、助けていただければ幸いです。
つまり、アプリケーションが最初に起動され、ユーザーが何も選択しなかったときのように、配列を更新する必要があります。
これは私がそれをリフレッシュする必要がある部分です。
if ([gradeRecieved objectAtIndex:i]==nil) {
break; // if this condition is met the program must begin anew.
編集*-(void)viewDidLoadメソッドを思い出す必要があります
ここにコードの詳細があります。
-(IBAction)button:(id)sender{
double sum = 0;
int i = 0;
double gradeEarned=0;
double creditHours = 3;
while (i<8){
// [credits removeObjectIdenticalTo:[NSNull null]];
if ([credits count ] ==0) {
break;
}
if ([credits objectAtIndex:i] == radioButtonA) {
// [gradeRecieved replaceObjectAtIndex:i withObject:GradeA];
[defArray addObject:GradeA];
gradeEarned+=GradeA.intValue;
i++;
continue;
}
if ([credits objectAtIndex:i] == radioButtonB) {
// [gradeRecieved replaceObjectAtIndex:i withObject:GradeB];
[defArray addObject:GradeB];
gradeEarned+=GradeB.intValue;
i++;
continue;
}
if ([credits objectAtIndex:i]== radioButtonC){
// [gradeRecieved replaceObjectAtIndex:i withObject:GradeC];
[defArray addObject:GradeC];
gradeEarned+=GradeC.intValue;
i++;
continue;
}
if ([credits objectAtIndex: i] == defaulter) {
UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"Custom button pressed" message:[NSString stringWithFormat:@"You pressed the custom button C"] delegate:self cancelButtonTitle:@"great"otherButtonTitles:nil];
[alert show];
[alert release];
[self viewDidLoad];
break;
}
}
if ([defArray count]>0) {
sum= ([defArray count])/(creditHours*gradeEarned);
NSLog(@"%f",sum);}
ただし、この新しいコードでは、ユーザーがボタンをクリックしてから、選択した内容をやり直そうとすると、アプリがフリーズします。