我正在制作的应用程序使用多个视图。例如免责声明视图,显示答案的视图等等。到目前为止,这是我一直用来从一个视图切换到另一个视图的代码
-(IBAction)swichtogain:(id)sender{
gainview *second = [[gainview alloc]initWithNibName:nil bundle:nil];
[self presentModalViewController:second animated:YES];
[second release];
}
我在教程中找到了这种方法,我想知道,这是最好的方法吗?例如,我使用相同的代码从一个视图向后切换到另一个视图。
-(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 文件中编辑任何内容,这是一个基于视图的应用程序。这种方法是否会导致它使用更多内存?在使用仪器进行活动监视器测试期间,我注意到每次从主菜单转到另一个视图并返回主菜单时内存使用量都会增加!还有比这更好的方法吗?还有一个视图是计算器,所以当用户点击计算按钮时,它会切换到下一个视图,同时将文本字段更改为答案,下面是代码!
-(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];
}