0

I need to use the LoadUrl method of the FFImageLoading ImageService class synchronously since it is called in a CreateCell method of a data source for a grid. Using Xamarin.iOS and c#. Appreciate a quick solution. Here is the current code:

public override IGFlowLayoutViewCell CreateCell(IGFlowLayoutView flowLayoutView, nint index)
        {
            IGFlowLayoutViewCell cell = flowLayoutView.DequeueReusableCell("CELL") as IGFlowLayoutViewCell;
            UIImageView iconImage = new UIImageView();

            if (cell == null)
            {
                cell = new IGFlowLayoutViewCell("CELL");
                cell.ContentInset = new UIEdgeInsets(2, 2, 2, 2);
                cell.ContentMode = UIViewContentMode.Center;
                cell.Layer.BorderColor = UIColor.LightGray.CGColor;
                cell.Layer.BorderWidth = 1;

                cell.ContentView = iconImage;

                ImageService.LoadUrl(instrumentImageUrls[index], new TimeSpan(12, 0, 0))
                            .Into((UIImageView)cell.ContentView,0);
            }

            return cell;
        }
Cœur
  • 37,241
  • 25
  • 195
  • 267
  • 2
    Not sure you can and even if you could I would advise against it. This would mean you app would freeze every time the your app called CreateCell. You should just use a placeholder if you don't want to show an empty view while the image loads. – Andres Castro May 06 '16 at 16:55
  • Agree in a classical context. This is a dashboard running on an iPad Pro or on an AppleTV with no user input. So the question remains. – Halil Doğan Bolak May 12 '16 at 10:06

1 Answers1

0
public override IGFlowLayoutViewCell CreateCell(IGFlowLayoutView flowLayoutView, nint index)
        {
            IGFlowLayoutViewCell cell = flowLayoutView.DequeueReusableCell("CELL") as IGFlowLayoutViewCell;
            UIImageView iconImage = new UIImageView();

            if (cell == null)
            {
                cell = new IGFlowLayoutViewCell("CELL");
                cell.ContentInset = new UIEdgeInsets(2, 2, 2, 2);
                cell.ContentMode = UIViewContentMode.Center;
                cell.Layer.BorderColor = UIColor.LightGray.CGColor;
                cell.Layer.BorderWidth = 1;

                cell.ContentView = iconImage;

                ImageService.LoadUrl(instrumentImageUrls[index], new TimeSpan(12, 0, 0))
                            .IntoAsync((UIImageView)cell.ContentView,0).GetAwaiter().GetResult();
            }

            return cell;
        }
Daniel Luberda
  • 7,374
  • 1
  • 32
  • 40