2016-05-06 3 views
0

Мне нужно использовать метод LoadUrl класса FFImageLoading ImageService синхронно, так как он вызывается в методе CreateCell источника данных для сетки. Использование Xamarin.iOS и C#. Оцените быстрое решение. Вот текущий код:Использование FFImageLoading синхронно?

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; 
     } 
+2

Не уверен, что вы можете и даже если я мог бы посоветовать против него. Это означало бы, что приложение будет зависать каждый раз, когда ваше приложение называется CreateCell. Вы должны просто использовать заполнитель, если вы не хотите показывать пустой вид во время загрузки изображения. –

+0

Согласитесь в классическом контексте. Это панель управления, работающая на iPad Pro или на AppleTV без ввода пользователем. Поэтому вопрос остается. –

ответ

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; 
     } 
Смежные вопросы