私が作っているアプリは複数のビューを利用しています。免責事項ビュー、回答を表示するビューなど。これまで、あるビューから別のビューに切り替えるために使用していたコードです。
-(IBAction)swichtogain:(id)sender{
gainview *second = [[gainview alloc]initWithNibName:nil bundle:nil];
[self presentModalViewController:second animated:YES];
[second release];
}
チュートリアルでこの方法を見つけましたが、これが最善の方法でしょうか? たとえば、同じコードを使用して、あるビューから別のビューに n 前後に切り替えます。
-(IBAction)swichtoview1:(id)sender{
view1 *view = [[gainview alloc]initWithNibName:nil bundle:nil];
[self presentModalViewController:view animated:YES];
[view release];
}
そしてview1でユーザーが戻るボタンを押すと、次のコードが実行されます
-(IBAction)swichtomainview:(id)sender{
mainview *view = [[gainview alloc]initWithNibName:nil bundle:nil];
[self presentModalViewController:view animated:YES];
[view release];
}
appdelegate ファイルは何も編集していません。これはビュー ベースのアプリです。この方法により、より多くのメモリが使用されますか? インスツルメントを使用したアクティビティモニターのテスト中に、メインメニューから別のビューに移動してメインメニューに戻るたびに、メモリ使用量が高くなることに気付きました!. これよりも良い方法はありますか?また、ビューの 1 つは電卓であるため、ユーザーが計算ボタンを押すと、テキスト フィールドを回答に変更しながら次のビューに切り替わります。以下はそのコードです。
-(IBAction)calculate{
MyClass *setnum = [[MyClass alloc]init];
setnum.grade_num = grade;
setnum.stage_num = stage;
setnum.ex_lym = ex_ly;
setnum.pos_lym = pos_ly;
setnum.er_num = er;
setnum.noderatio = pos_ly/ex_ly;
if(text1.text.length <=0 ||text2.text.length <=0||text3.text.length<=0||text4.text.length<=0||text5.text.length <=0){
UIActionSheet *action = [[UIActionSheet alloc]initWithTitle:@"Incomplete Values" delegate:self cancelButtonTitle:@"Ok" destructiveButtonTitle:nil otherButtonTitles:nil];
[action showInView:self.view];
[action release];
}else{
answer *ans =[[answer alloc]initWithNibName:nil bundle:nil];
[self presentModalViewController:ans animated:YES];
float i = calc_gain(setnum.grade_num, setnum.noderatio, setnum.stage_num, setnum.er_num);
NSString *result = [NSString stringWithFormat:@"%f",i];
ans.answer1.text = result;
ans.bar.hidden = NO;
[ans release];
}
[setnum release];
}