UICollectionView scrolling hangs when nothing to scroll

LochanGabdaLochanGabda ✭✭USMember ✭✭

Hi,

I am facing one weird issue. When there is nothing to scroll in UICollectionVIew, the app hangs on scrolling. I dont know how to solve this.
Anybody faced this issue? any help? Thanks in advance.

Regards.

Posts

  • JakovljevicIgorJakovljevicIgor ✭✭✭ USMember ✭✭✭

    @LochanGabda Could you give us more information or pictures. I am having troubles undestanding the problem. Does the scroll keep going even though you do not have elements ?

  • LochanGabdaLochanGabda ✭✭ USMember ✭✭
    edited July 2017

    @JakovljevicIgor, UICollectionView has only 6 items, all are visible on the screen. In such cases if user tries to scroll the window for multiple times, app hangs.

  • JakovljevicIgorJakovljevicIgor ✭✭✭ USMember ✭✭✭

    @LochanGabda How did you implement the reuse of cells ? What did you place in the cell?

    public override UICollectionViewCell GetCell(UICollectionView collectionView, NSIndexPath indexPath)
    {
    // CategoryPreviewImageCell should be the name of you cell class
    var cell = (CategoryPreviewImageCell) collectionView.DequeueReusableCell(CellName, indexPath);
    //Todo: Add your cell customisation code
    return cell;
    }

  • LochanGabdaLochanGabda ✭✭ USMember ✭✭

    @JakovljevicIgor, I am using custom cell layout using flow layout.

    public override UICollectionViewCell GetCell(UICollectionView collectionView, NSIndexPath indexPath)
    {
    var cell = collectionView.DequeueReusableCell(reuseIdentifier, indexPath) as CustomCell;
    cell.PrepareForReuse();
    cell.UpdateConstratints();
    return cell;
    }

    Custom Cell creation is as below:

    private nfloat ContentViewWidth = 250.0f;
    private nfloat ContentViewHeight = 270.0f;

    [Export("initWithFrame:")]
    public CustomCell(CGRect frame) : base(frame)
    {
    ContentView.Layer.BorderColor = UIColor.Black.CGColor;
    ContentView.Layer.BorderWidth = 1.0f;

            ContentView.Frame = new CGRect(0, 0, ContentViewWidth, ContentViewHeight);
    
            imageView = new UIImageView();
        imageView.Image = UIImage.FromFile("...");
            imageView.Center = ContentView.Center;            
            imageView.ContentMode = UIViewContentMode.ScaleAspectFill;
            imageView.ClipsToBounds = true;     
        ContentView.AddSubview(imageView);       
    
            labelHeading = new UILabel();
            labelHeading.Text = "Name";
            labelHeading.TextColor = UIColor.Black;
            labelHeading.Font = UIFont.PreferredHeadline;
            labelHeading.TextAlignment = UITextAlignment.Left;
            labelHeading.LineBreakMode = UILineBreakMode.WordWrap;
            labelHeading.Lines = 0;
            labelHeading.SizeToFit();
            ContentView.AddSubview(labelHeading);
    
            labelSubTitle = new UILabel();
            labelSubTitle.Text = "Type";
            labelSubTitle.TextColor = UIColor.Black;
            labelSubTitle.Font = UIFont.PreferredHeadline;
            labelSubTitle.TextAlignment = UITextAlignment.Left;
            labelSubTitle.LineBreakMode = UILineBreakMode.WordWrap;
            labelSubTitle.SizeToFit();
            ContentView.AddSubview(labelSubTitle);
    

    }

    I haven't done anything new. Its a simple layout.

  • JakovljevicIgorJakovljevicIgor ✭✭✭ USMember ✭✭✭

    Try just writing only declaration things in the custom cell class and the assignments to these into the UICollectionViewCell GetCell.

    public partial class CustomCell: UICollectionViewCell
    {
    public CategoryPreviewImageCell (IntPtr handle) : base (handle)
    {
    }

        public UILabel labelHeading => labelHeading;
    
    }
    
  • LochanGabdaLochanGabda ✭✭ USMember ✭✭

    Hi @JakovljevicIgor, thanks for the suggestion. I tried this, however the app still hangs.

Sign In or Register to comment.