how to make the app running well
i have some UIViews,and there are some buttons on the first UIView,the click function of them likes this
-(IBAction)securityClicked:(id)sender
{
SwitchViewController* switchViewController = (SwitchViewController*)[wangfan_chevyAppDelegate App].viewController;
[switchViewController.wtccviewcontroller.scrollView1 setContentOffset:CGPointMake(
1024*0, 0) animated:false];
[[testAppDelegate App] pushViewFromRight:switchViewController.wtccviewcontroller
over:self];
}
and the wtccviewcontroller.m file's code is
- (void)viewDidLoad {
[super viewDidLoad];
UIViewController* controller = nil;
controller = [[Wtcc1ViewController alloc]initWithNibName:@"Wtcc1ViewController" bundle:nil];
controller.view.frame = CGRectMake(1024*0, 0, 1024, 768);
[scrollView1 addSubview:controller.view];
//[controller release];
controller = [[Wtcc2ViewController alloc]initWithNibName:@"Wtcc2ViewController" bundle:nil];
controller.view.frame = CGRectMake(1024*1, 0, 1024, 768);
[scrollView1 addSubview:controller.view];
//[controller release];
controller = [[Wtcc3ViewController alloc]initWithNibName:@"Wtcc3ViewController" bundle:nil];
controller.view.frame = CGRectMake(1024*2, 0, 1024, 768);
[scrollView1 addSubview:controller.view];
//[controller release];
controller = [[Wtcc4ViewController alloc]initWithNibName:@"Wtcc4ViewController" bundle:nil];
controller.view.frame = CGRectMake(1024*3, 0, 1024, 768);
[scrollView1 addSubview:contr开发者_开发知识库oller.view];
//[controller release];
controller = [[SecurityViewController alloc]initWithNibName:@"SecurityViewController" bundle:nil];
controller.view.frame = CGRectMake(1024*4, 0, 1024, 768);
[scrollView1 addSubview:controller.view];
//[controller release];
controller = [[Security2ViewController alloc]initWithNibName:@"Security2ViewController" bundle:nil];
controller.view.frame = CGRectMake(1024*5, 0, 1024, 768);
[scrollView1 addSubview:controller.view];
//[controller release];
controller = [[Onstar1ViewController alloc]initWithNibName:@"Onstar1ViewController" bundle:nil];
controller.view.frame = CGRectMake(1024*6, 0, 1024, 768);
[scrollView1 addSubview:controller.view];
//[controller release];
controller = [[Movie1ViewController alloc]initWithNibName:@"Movie1ViewController" bundle:nil];
controller.view.frame = CGRectMake(1024*7, 0, 1024, 768);
[scrollView1 addSubview:controller.view];
//[controller release];
controller = [[CarownerViewController alloc]initWithNibName:@"CarownerView" bundle:nil];
controller.view.frame = CGRectMake(1024*8, 0, 1024, 768);
[scrollView1 addSubview:controller.view];
//[controller release];
controller = [[Co01ViewController alloc]initWithNibName:@"Co01ViewController" bundle:nil];
controller.view.frame = CGRectMake(1024*9, 0, 1024, 768);
[scrollView1 addSubview:controller.view];
controller = [[Co02ViewController alloc]initWithNibName:@"Co02ViewController" bundle:nil];
controller.view.frame = CGRectMake(1024*10, 0, 1024, 768);
[scrollView1 addSubview:controller.view];
controller = [[Co03ViewController alloc]initWithNibName:@"Co03ViewController" bundle:nil];
controller.view.frame = CGRectMake(1024*11, 0, 1024, 768);
[scrollView1 addSubview:controller.view];
controller = [[Co04ViewController alloc]initWithNibName:@"Co04ViewController" bundle:nil];
controller.view.frame = CGRectMake(1024*12, 0, 1024, 768);
[scrollView1 addSubview:controller.view];
controller = [[Co05ViewController alloc]initWithNibName:@"Co05ViewController" bundle:nil];
controller.view.frame = CGRectMake(1024*13, 0, 1024, 768);
[scrollView1 addSubview:controller.view];
controller = [[Co06ViewController alloc]initWithNibName:@"Co06ViewController" bundle:nil];
controller.view.frame = CGRectMake(1024*14, 0, 1024, 768);
[scrollView1 addSubview:controller.view];
controller = [[Co07ViewController alloc]initWithNibName:@"Co07ViewController" bundle:nil];
controller.view.frame = CGRectMake(1024*15, 0, 1024, 768);
[scrollView1 addSubview:controller.view];
controller = [[ConfigViewController alloc]initWithNibName:@"ConfigViewController" bundle:nil];
controller.view.frame = CGRectMake(1024*16, 0, 1024, 768);
[scrollView1 addSubview:controller.view];
[scrollView1 setContentSize:CGSizeMake(1024*17,768)];
}
because there are a lot of controllers,so when i click the button on the first view,it will be loaded so long,even quit the app,so how should i do for make it running well?
At least three major issues with your code:
- You are leaking objects like crazy. You are allocating multiple view controllers but never releasing them. In fact, since you are reassigning the
controller
variable, you are losing a reference to those objects so that you can never release them. - Do not use multiple
UIViewController
objects to control parts of a single view. The view controller is designed and intended to be used full-screen (or as part of aUINavigationController
,UITabBarController
, etc). You should be using individualUIView
objects and controlling them from a central controller object and/or using your own lightweight view controllers. - Your final view size is something like 8192x768; that is massive. At the very least you can use a
UITableViewController
to intelligently cache parts of your view. This screen should probably be broken apart into smaller views, though.
First of all, if you call [alloc] you create an object (for each controller) then you must release it. You can do this after adding the subview since this retains it.
I see you commented out the [controller release] some times and then totally forgot about it.
Also you're adding a lot of controllers here. You could add the first in viewDidLoad and load lazily each other controller only when clicked.
精彩评论