UICollectionView reloading not properly

时间:2015-05-08 09:55:30

标签: ios objective-c uicollectionview uicollectionviewcell

I have that kind of requirement, if user has selected 1 then I have to display images (which is in collection view cell) by rotating at 90 degree and if user had selected 4 then I have to display images as round. For selection 2 and 3 display image as it is.
For that I written below code.

self.addEventListener('message', function(e) {
    function load(url){
        var xmlhttp=new XMLHttpRequest();
        xmlhttp.onreadystatechange=function()
        {
            if (xmlhttp.readyState==4 && xmlhttp.status==200)
            {
                console.log(xmlhttp);
                self.postMessage({'url':url});
            }
        }
        xmlhttp.open("GET",url,true);
        xmlhttp.send();
    }

    var urls = e.data.args[0];
    for(var i = 0; i<urls.length; i++){
        load(urls[i]);
    }
}, false);

and on selection 1,2,3 or 4 I'm reloading collection view.

The problem is that if user selected 4 after selecting 1 then some of images after displays rotated and after that if user selects 2 or 3 some images rotated and some images circle. I have tried to delete section before reloading as per mention here but app crashes and log is

*** Assertion failure in -[UICollectionView _endItemAnimations], /SourceCache/UIKit/UIKit-3318.93/UICollectionView.m:3917

reloading code is as below:

console.log();

UPDATE: If tried to using
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath { FilterCell *cell = (FilterCell *)[collectionView dequeueReusableCellWithReuseIdentifier:@"filterCell" forIndexPath:indexPath]; if (!cell) { cell = [[FilterCell alloc] init]; } if (filterScreen==1) { cell.imgView.image = [collectionImage objectAtIndex:indexPath.row]; cell.imgView.transform = CGAffineTransformMakeRotation(M_PI_2); } else if (filterScreen==2) { cell.imgView.image = [UIImage imageNamed:[NSString stringWithFormat:@"filter_%ld",(long)indexPath.row]]; } else if (filterScreen==3) { cell.imgView.image = [UIImage imageNamed:[NSString stringWithFormat:@"motiontitle_contents_%ld",(long)indexPath.row]]; } else if (filterScreen==4) { cell.imgView.image = [UIImage imageNamed:[NSString stringWithFormat:@"bgm_%ld",(long)indexPath.row]]; cell.imgView.layer.cornerRadius = cell.imgView.frame.size.height /2; cell.imgView.layer.masksToBounds = YES; } return cell; }
then getting

*** Assertion failure in -[UICollectionView _endItemAnimations], /SourceCache/UIKit/UIKit-3318.93/UICollectionView.m:3901

can anyone help me to solve this?

1 个答案:

答案 0 :(得分:2)

Okay it took a while for me to understand your problem.

First, the solution you are trying is wrong. You want to reload a section but delete it instead (try <%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <%@ taglib prefix="s" uri="/struts-tags" %> <html> <head> </head> <body> This is a test page... <p> should show firstname and lastname: <s:property value="firstname"/> <s:property value="lastname"/> </p> </body> </html> instead).

However, that won't solve your problem either. Cells are reused and you never reset the import com.opensymphony.xwork2.ActionSupport; public class Basic extends ActionSupport{ private String firstname = "me"; private String lastname = "I"; public String getFirstname() { return firstname; } public void setFirstname(String firstname) { this.firstname = firstname; } public String getLastname() { return lastname; } public void setLastname(String lastname) { this.lastname = lastname; } public String execute() { return SUCCESS; } } property. Try this:

reloadSections