誰かがこれで私を助けてくれることを願っています:
リモートデータを表示するアプリがあります。データは、あるイベントで演奏するアーティストのリストを含む json 応答で構成されます。
各アーティストには、tableView に表示したい写真があります。
これを行うための最適化された方法を探しています画像をキャッシュし、セルを非同期的に作成します
これが私がこれまでに行ったことです:
私のテーブルビュー
class LineupTableViewController < UITableViewController
  attr_accessor :artists
  #attr_accessor :table
  def init
    super
    self.title = 'Line-up'
    self.initWithNibName(nil, bundle:nil)
    self.view.styleId = 'lineUpView'
    self.tabBarItem = UITabBarItem.alloc.initWithTitle("LineUp", image: UIImage.imageNamed("112-group.png"), tag:2)    
    self
  end
  def viewWillAppear(animated)
    view.dataSource = view.delegate = self
    @artists = []
    App::Persistence['event']['artists'].each do |artist|
      @artists.push(Artist.new(artist)) unless artist["dj"]
    end
  end
  def viewDidLoad
    super
    view.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight
  end
def tableView(tableView, cellForRowAtIndexPath: indexPath)
  artist = @artists[indexPath.row]
  ArtistCell.cellForArtist(artist, indexPath:indexPath, inTableView:tableView)      
end
def tableView(tableView, numberOfRowsInSection: section)
  @artists.length
end
def tableView(tableView, didSelectRowAtIndexPath:indexPath)
  detailViewController = ArtistsdetailViewController.alloc.initWithArtist(@artists[indexPath.row])   
  self.navigationController.pushViewController(detailViewController, animated:true)   
end
def tableView(tableView, heightForRowAtIndexPath:indexPath)
     80
end  
#def reloadRowForIndexPath(indexPath)
#  puts "indexPath.section #{indexPath.section}"
#  self.view.reloadRowsAtIndexPaths([NSIndexPath.indexPathForRow(indexPath.row, inSection:indexPath.section)], withRowAnimation:false)
#end
end
カスタムセル
class ArtistCell < UITableViewCell
  attr_accessor :index_path
  CellId = "ArtistCellIdentifier"  
  def setSelected(selected, animated:animated)
    super
    # Configure the view for the selected state
  end
  def self.cellForArtist(artist, indexPath:indexPath, inTableView:tableView)
    cell = tableView.dequeueReusableCellWithIdentifier(ArtistCell::CellId) || ArtistCell.alloc.initWithStyle(UITableViewCellStyleSubtitle, reuseIdentifier:CellId)
      #puts "indexPath #{}"
      cell.index_path = indexPath
      cell.fillArtist(artist, inTableView:tableView)    
    cell
  end
  def fillArtist(artist, inTableView:tableView)
    #Dispatch::Queue.concurrent.async do      
     #  Dispatch::Queue.main.sync do
        self.textLabel.text = artist.name
        self.detailTextLabel.text = artist.country
        JMImageCache.sharedCache.imageForURL(NSURL.URLWithString(artist.picture), completionBlock:proc {
          |downloaded_image|      
            self.imageView.image = downloaded_image
        })
      # end
    #end     
  end
end
私が今得たものは次のとおりです。
- 表示されたセルをタップしないと画像が表示されない
- ビューを下にスクロールすると、非表示のセルの画像が表示されるので、上にスクロールするとすべての画像が表示されます。
これを解決する助けがあれば、FFに感謝します