我要求你在我的應用程序的內存問題的幫助!低內存警告與幾個EGOImageView
我在表格中有一個單元格,其中包含一個或多個EGOImageView
s的水平滾動視圖。此單元格始終位於第0行,但我經常需要用另一個Image重新加載此單元格。
的問題是:當我重裝我的手機太多的時間(30或40倍),我收到一個內存警告或時有時無的錯誤和應用程序崩潰...
我使用ARC國防部。這裏是我的代碼預覽:
單元代碼爲行0
GalleryDetailCell *cell = (GalleryDetailCell *) [tableView dequeueReusableCellWithIdentifier: @"GalleryAnimated"];
if (cell == nil) {
cell = [[GalleryDetailCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier: @"GalleryAnimated" animated:animated];
}
[cell configureGallery:id];
cellToReturn = cell;
你有任何想法,我的錯誤是
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier animated:(BOOL)animated{
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self) {
// Initialization code
[self.contentView setFrame:CGRectMake(0, 0, 320, 240)];
self.scrollView = [[UIScrollView alloc]initWithFrame:CGRectMake(0, 0, 320, 240)];
[self.scrollView setDelegate:self];
[self.scrollView setPagingEnabled:YES];
[self.scrollView setShowsHorizontalScrollIndicator:NO];
self.scrollView.contentSize = CGSizeMake(320, 240);
pageControl = [[UIPageControl alloc]initWithFrame:CGRectMake(0, 220, 320, 20)];
[pageControl setCurrentPage:0];
[self.contentView addSubview:self.scrollView];
[self.contentView addSubview:pageControl];
isAnimated= animated;
return self;
}
- (void)configureGallery:(NSInteger)accommodationId{
counter =0;
Accommodation *item = [[[DataManager sharedManager]accommodations]objectAtIndex:accommodationId];
numberPictures = [[item photo_set]count];
if (numberPictures >1) {
[scrollView setContentSize:CGSizeMake((numberPictures + 2)*320, 240)];
} else [scrollView setContentSize:CGSizeMake(320, 240)];
[pageControl setNumberOfPages:numberPictures];
// add the last image into the first position
if (numberPictures) {
[self addImageWithName:[NSString stringWithFormat:@"%@%@",[[DataManager sharedManager]baseUrl],[[item.photo_set objectAtIndex:numberPictures-1]thumbnail_gallery]] atPosition:0];
}
// add all of the images to the scroll view
for (int i = 0; i < numberPictures; i++) {
[self addImageWithName:[NSString stringWithFormat:@"%@%@",[[DataManager sharedManager]baseUrl],[[item.photo_set objectAtIndex:i]thumbnail_gallery]] atPosition:i+1 ];
}
// add the first image into the last position
[self addImageWithName:[NSString stringWithFormat:@"%@%@",[[DataManager sharedManager]baseUrl],[[item.photo_set objectAtIndex:0]thumbnail_gallery]] atPosition:numberPictures+1];
[self.scrollView scrollRectToVisible:CGRectMake(320,0,320,416) animated:NO];
[self performSelector:@selector(switchToNextPhoto) withObject:nil afterDelay:5];
}
- (void)addImageWithName:(NSString*)imageString atPosition:(int)position {
// add image to scroll view
UIImageView * placeHolderView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"France"]];
[placeHolderView setFrame:CGRectMake(position*320, 0, 320, 240)];
UIActivityIndicatorView * activityView = [[UIActivityIndicatorView alloc]initWithFrame:CGRectMake((position*320)+160, 120, 20, 20)];
[activityView startAnimating];
EGOImageView *imageView = [[EGOImageView alloc] init];
imageView.frame = CGRectMake(position*320, 0, 320, 240);
[self.scrollView addSubview:placeHolderView];
[self.scrollView addSubview:activityView];
[self.scrollView addSubview:imageView];
imageView.imageURL = [NSURL URLWithString:imageString];
}
表的代碼?當我重新加載我的細胞時,是否必須手動處理我的EGOImageView
並將它們放到nil
?
謝謝你的時間!
謝謝你的回答,我明天會測試它並給你我的反饋! – palmitoto 2012-08-07 17:36:08