私はテキストフィールドを持っていますそのユーザーは1から10までの値を入力できます
テキストフィールドの下部にボタンがあります。
ユーザーが[完了]ボタンをクリックしたときに、配列にファイルされたテキストの値を追加する必要があります
このために私はこのようなコードを書きました。
- (void)viewDidLoad
{
[super viewDidLoad];
PainlevelsArray = [[NSMutableArray alloc] init]; //PainlevelsArray declared in .h
}
-(IBAction)doneClick:(id)sender
{
[PainlevelsArray addObject:txtField.text ];
// [PainlevelsArray insertObject:rateLabel.text atIndex:0 ];
NSLog(@"PainlevelsArray *** %@",PainlevelsArray);
[self.navigationController popToRootViewControllerAnimated:YES];
}
ただし、このように、ボタンがクリックされたときに、配列がログに最近追加された1つの値のみを表示するたびに
コンソールでの出力
========================
2012-05-07 10:11:15.689 ESPT[796:10d03] PainlevelsArray *** (
2
)
2012-05-07 10:11:27.984 ESPT[796:10d03] PainlevelsArray *** (
4
)
My array gets empty every time view loads, and adde a fresh entry when button clicks
しかし、私はこのようにする必要があります
2012-05-07 10:11:27.984 ESPT[796:10d03] PainlevelsArray *** (
4,
5,
2,
6,
8,
)
入力されたすべてのビューは、既存のアレイに追加/挿入されます。
前もって感謝します
ExerciseStartViewControllerで
-(void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
ExerciseResult *result = [[ExerciseResult alloc] init];
[self.navigationController pushViewController:result animated:YES];
[result release];
}
現在/ExerciseResultビューコントローラで
- (void)viewDidLoad
{
[super viewDidLoad];
PainlevelsArray = [[NSMutableArray alloc] init]; //PainlevelsArray declared in .h
}
-(IBAction)doneClick:(id)sender
{
[PainlevelsArray addObject:txtField.text ];
// [PainlevelsArray insertObject:rateLabel.text atIndex:0 ];
NSLog(@"PainlevelsArray *** %@",PainlevelsArray);
[self.navigationController popToRootViewControllerAnimated:YES];
}