奇数滚动问题(UIScrollView)

时间:2011-02-21 15:07:00

标签: iphone objective-c cocoa-touch ipad ios

我无休止地搜索到这一点无济于事,希望有人可以提供帮助!

我在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

1 个答案:

答案 0 :(得分:0)

对于将来遇到此问题的任何人,一旦我开始在实际设备上测试内容,一切都非常顺利。也许这只是模拟器的奇特之处?我会考虑解决这个问题,尽管我还是会进一步研究它。