0

My CollectionView извлекает изображения из сети Parse и продолжает сбой. Я продолжаю получать предупреждения о памяти прямо перед сбоем. Я предполагаю, что мне нужно освободить место. Но проблема в том, что я относительно новичок в кодировании, поэтому я не знаю, как это сделать. Я даже не знаю, откуда должна быть освобождена память. Может кто-то, пожалуйста, помогите мне понять, что я делаю неправильно в своем коде?UICollectionView Ошибка утечки памяти

  - (void)viewDidLoad { 
    [super viewDidLoad]; 


    [[UINavigationBar appearance] setBackgroundImage:[UIImage imageNamed:@"NavBar1.png"] forBarMetrics:UIBarMetricsDefault]; 


    // self.navigationController.hidesBarsOnSwipe = true; 

    [self queryParseMethodCell]; 

    // Do any additional setup after loading the view. 
} 


- (void)queryParseMethodCell { 
    NSLog(@"start Money"); 
    PFQuery *query3 = [PFQuery queryWithClassName:@"MainWall"]; 
    PFQuery *query4 = [PFQuery queryWithClassName:@"MainWall"]; 

    [query3 orderByDescending:@"createdAt"]; 
    [query4 orderByAscending:@"createdAt"]; 

    [query3 findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error)  { 
    if (!error) { 
     NSLog(@"check bobby"); 

     imageFilesArray2 = [[NSArray alloc] initWithArray:objects]; 

     [self.HomePost reloadData]; 

    } 
    else{ 

     NSLog(@"NO Good33"); 
    } 


}]; 
    [query4 findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) { 
    if (!error) { 
     NSLog(@"check bobby"); 

     imageFilesArray3 = [[NSArray alloc] initWithArray:objects]; 

     [self.HomePost reloadData]; 

    } 
    else{ 

     NSLog(@"NO Good44"); 
    } 


    }]; 

    } 

-(void)scrollViewDidScroll:(UIScrollView *)scrollView { 


    if (self.lastContentOffset > scrollView.contentOffset.y) { 
     [self.navigationController setNavigationBarHidden:NO animated:YES]; 

    } 

    else if (self.lastContentOffset < scrollView.contentOffset.y){ 

    [self.navigationController setNavigationBarHidden:YES animated:YES]; 


    } 

    else { 

     NSLog(@"Andy Error1"); 

    } 

} 

- (IBAction)SwipeLeft:(UISwipeGestureRecognizer *)sender { 

    [self performSegueWithIdentifier:@"Notifications" sender:self]; 

} 
- (IBAction)SwipeRight:(UISwipeGestureRecognizer *)sender{ 

    [self performSegueWithIdentifier:@"FavWall" sender:self]; 

    } 


- (IBAction)MainWall:(id)sender{ 

    [self performSegueWithIdentifier:@"MainWall" sender:self]; 

} 

- (IBAction)FavWall:(id)sender{ 

    [self performSegueWithIdentifier:@"FavWall" sender:self]; 

} 

- (IBAction)Notifications:(id)sender{ 

    [self performSegueWithIdentifier:@"Notifications" sender:self]; 

} 

- (IBAction)Home:(id)sender{ 

    [self performSegueWithIdentifier:@"Home" sender:self]; 

} 

- (IBAction)YourAccount:(id)sender{ 

    [self performSegueWithIdentifier:@"YourAccount" sender:self]; 

} 

- (IBAction)UsersAccount:(id)sender{ 

    [self performSegueWithIdentifier:@"UsersAccount" sender:self]; 

} 

-(IBAction)PicTake:(id)sender{ 


    [self performSegueWithIdentifier:@"Camera" sender:self]; 

} 





#pragma mark Collection View 
-(NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView { 

    return 1; 

} 

-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section { 

    return [imageFilesArray2 count]; 

} 

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath { 



    static NSString *cellIdentifier = @"TopCell"; 

    DiscoverCell *cell = nil; 

    if (cell == nil) { 

     cell = (DiscoverCell *)[collectionView dequeueReusableCellWithReuseIdentifier:cellIdentifier forIndexPath:indexPath]; 

    } 
    else { 

     NSLog(@"2Error"); 
    } 



    PFObject *imageObject2 = [imageFilesArray2 objectAtIndex:indexPath.row]; 
    cell.Username.text = [imageObject2 objectForKey:@"Name"]; 


    PFFile *imageFile3 = [imageObject2 objectForKey:@"ProfilePicture"]; 



    [imageFile3 getDataInBackgroundWithBlock:^(NSData *data, NSError *error) { 
    if (!error) { 
     NSLog(@"CheckCash"); 




     // cell.TopStory.image = [UIImage imageWithData:data]; 
     cell.HomeImg.image = [UIImage imageWithData:data]; 
     cell.Back.image = [UIImage imageWithData:data]; 
     //cell.HomeImg2.image = [UIImage imageWithData:data]; 




    } 
    else{ 

     NSLog(@"NO Good"); 
    } 

    cell.HomeImg.layer.cornerRadius = cell.HomeImg.frame.size.width /2; 
    cell.HomeImg.clipsToBounds = YES; 
    cell.Back.image = cell.HomeImg.image; 

    }]; 

    PFObject *imageObject5 = [imageFilesArray3 objectAtIndex:indexPath.row]; 
    cell.Username.text = [imageObject5 objectForKey:@"Name"]; 


    PFFile *imageFile4 = [imageObject5 objectForKey:@"ProfilePicture"]; 

    [imageFile4 getDataInBackgroundWithBlock:^(NSData *data, NSError *error) { 
     if (!error) { 
      NSLog(@"CheckCash"); 




      cell.TopStory.image = [UIImage imageWithData:data]; 



    } 
    else{ 

     NSLog(@"NO Good22"); 
    } 


}]; 


    return cell; 

} 



- (void)didReceiveMemoryWarning { 
    [super didReceiveMemoryWarning]; 
    // Dispose of any resources that can be recreated. 
} 



@end 
+0

Не благодарите в своих вопросах. Мы хотим, чтобы вопрос был как можно более простым. Было бы очень неприятно, если бы все поблагодарили :) – Thellimist

+0

Слишком много пробелов, не могли прочитать. –

ответ

0

У вас есть утечка памяти. Каждый раз, когда вы просматриваете все загруженные изображения. Что-то вроде этого должно решить проблему

//at start For every data DataisNotLoaded should be true 

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath { 


if dataisNotLoaded[index] { 
     DataisNotLoaded[index] = false 

[imageFile3 getDataInBackgroundWithBlock:^(NSData *data, NSError *error) { 
    if (!error) { 
     NSLog(@"CheckCash"); 




     // cell.TopStory.image = [UIImage imageWithData:data]; 
     cell.HomeImg.image = [UIImage imageWithData:data]; 
     cell.Back.image = [UIImage imageWithData:data]; 
     //cell.HomeImg2.image = [UIImage imageWithData:data]; 




    } 
    else{ 

     NSLog(@"NO Good"); 
    } 

} 
+0

если dataisNotLoaded? как бы я это назвал? – Markinson

+0

Массив будет делать то задание, отредактированное nasnwer. – Thellimist

+0

Знаете ли вы, что вызывает цикл? – Markinson

Смежные вопросы