Objective c UICollectionView内存泄漏崩溃
我的CollectionView正在从解析网络检索图像,并不断崩溃。我一直在崩溃前收到内存警告。我想我需要腾出一些空间。但问题是我对编码还比较陌生,所以我不知道怎么做。我甚至不知道该从哪里释放内存。有人能帮我理解我在代码中做错了什么吗Objective c UICollectionView内存泄漏崩溃,objective-c,xcode,memory-management,parse-platform,uicollectionview,Objective C,Xcode,Memory Management,Parse Platform,Uicollectionview,我的CollectionView正在从解析网络检索图像,并不断崩溃。我一直在崩溃前收到内存警告。我想我需要腾出一些空间。但问题是我对编码还比较陌生,所以我不知道怎么做。我甚至不知道该从哪里释放内存。有人能帮我理解我在代码中做错了什么吗 - (void)viewDidLoad { [super viewDidLoad]; [[UINavigationBar appearance] setBackgroundImage:[UIImage imageNamed:@"N
- (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
-(void)viewDidLoad{
[超级视图下载];
[[UINavigationBar外观]setBackgroundImage:[UIImage ImageName:@“NavBar1.png”]forBarMetrics:UIBarMetricsDefault];
//self.navigationController.hidesBarsOnSwipe=true;
[自问parsemethodcell];
//加载视图后执行任何其他设置。
}
-(void)queryParseMethodCell{
NSLog(“启动资金”);
PFQuery*query3=[PFQuery queryWithClassName:@“MainWall”];
PFQuery*query4=[PFQuery queryWithClassName:@“MainWall”];
[query3 orderByDescending:@“createdAt”];
[query4 orderByAscending:@“createdAt”];
[query3 findObjectsInBackgroundWithBlock:^(NSArray*对象,NSError*错误){
如果(!错误){
NSLog(“检查鲍比”);
ImageFileArray2=[[NSArray alloc]initWithArray:objects];
[self.HomePost重新加载数据];
}
否则{
NSLog(@“NO Good33”);
}
}];
[query4 findObjectsInBackgroundWithBlock:^(NSArray*对象,NSError*错误){
如果(!错误){
NSLog(“检查鲍比”);
ImageFileArray3=[[NSArray alloc]initWithArray:objects];
[self.HomePost重新加载数据];
}
否则{
NSLog(@“NO Good44”);
}
}];
}
-(无效)scrollViewDidScroll:(UIScrollView*)scrollView{
if(self.lastContentOffset>scrollView.contentOffset.y){
[self.navigationController设置NavigationBarHidden:否动画:是];
}
else if(self.lastContentOffset
内存泄漏。每次滚动所有图像时,都会重新加载。这样的事情应该能解决问题
//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");
}
}
不要在你的问题上表示感谢。我们希望问题尽可能简单。如果每个人都感谢:)太多的空白,无法读取。如果数据未加载?我怎么称呼它?你知道是什么导致了循环吗?什么是导致循环的原因?你可以通过在cellForItemAtIndexPath中写入println来检查它,并查看它何时被调用。