我已经在这上面找了无数次也没有结果,希望有人能帮上忙!
我在UIView的左半部分有一个加载自定义单元格/子视图的UIScrollView。UIView是UINavigation堆栈的一部分,也被加载到TabBar上的选项卡中。
发生的情况是,如果我启动应用程序并立即开始滚动,它会非常流畅。然而,如果我启动应用程序并等待5-10秒,UIScrollView就会变得非常迟缓和不稳定(并且一直如此)。我会认为这可能是内存泄漏或其他什么,但我似乎找不到任何东西。
其中包含了将自定义单元格/子视图加载到UIScrollView中的视图的代码。单元格子视图中没有任何自定义代码。哦,而且只有8-10个项目:每个项目都有一个小的(150x150)图像和3个文本字段-都是不透明的。
#import "ProductListViewController.h"
#import "ProductListLeftItemViewController.h"
@implementation ProductListViewController
@synthesize listScroll;
- (void)viewDidLoad {
NSBundle *bundle = [NSBundle mainBundle];
NSString *path = [bundle pathForResource:@"Products" ofType:@"plist"];
NSArray *products = [[NSArray alloc] initWithContentsOfFile:path];
//
int numProducts;
numProducts = [products count];
[listScroll setContentSize:CGSizeMake(500, (numProducts * 111))];
for (int i = 0; i < numProducts; i++) {
ProductListLeftItemViewController *cellItem = [[ProductListLeftItemViewController alloc] initWithNibName:@"ProductListLeftItem" bundle:nil];
cellItem.view.frame = CGRectMake(0, (i*111), 500, 111);
[self.listScroll addSubview:cellItem.view];
cellItem = nil;
[cellItem release];
}
[products release];
[super viewDidLoad];
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return (interfaceOrientation == UIInterfaceOrientationLandscapeRight);
}
- (void)didReceiveMemoryWarning {
// Releases the view if it doesn't have a superview.
NSLog(@"Memory warning, ProductListViewController");
[super didReceiveMemoryWarning];
// Release any cached data, images, etc that aren't in use.
}
- (void)viewDidUnload {
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
- (void)dealloc {
[listScroll release];
[super dealloc];
}
@end按照要求,ProductListLeftItemViewController代码如下:
#import "ProductListLeftItemViewController.h"
@implementation ProductListLeftItemViewController
@synthesize titleTxt, descriptionTxt, modelTxt, productThumb;
// The designated initializer. Override if you create the controller programmatically and want to perform customization that is not appropriate for viewDidLoad.
/*
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization.
}
return self;
}
*/
/*
// Implement loadView to create a view hierarchy programmatically, without using a nib.
- (void)loadView {
}
*/
/*
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
[super viewDidLoad];
}
*/
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return YES;
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
}
- (void)viewDidUnload {
titleTxt = nil;
descriptionTxt = nil;
modelTxt = nil;
productThumb = nil;
[super viewDidUnload];
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
- (void)dealloc {
[titleTxt release];
[descriptionTxt release];
[modelTxt release];
[productThumb release];
[super dealloc];
}
@end发布于 2011-03-18 04:22:34
对于将来遇到这个问题的任何人来说,一旦我开始在实际设备上测试,一切都非常顺利。也许这只是模拟器的怪异之处?我会认为这个问题已经解决了,尽管我还会进一步研究它。
https://stackoverflow.com/questions/5067559
复制相似问题