###前提・実現したいこと
TableViewをスクロールしても、最初表示されていた画像が消えないように。
(cellの再描画が原因(?))
###該当のソースコード
Swift
1func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { 2 let cell = tableView.dequeueReusableCellWithIdentifier("MovieList", forIndexPath: indexPath) as! MovieListTableViewCell 3 4 // cell内の映画タイトルを設定 5 switch indexPath.section { 6 case 0: cell.movieListText?.text = movieListModel.movieListMonth1[indexPath.row]["title"]! as! String 7 case 1: cell.movieListText?.text = movieListModel.movieListMonth2[indexPath.row]["title"]! as! String 8 case 2: cell.movieListText?.text = movieListModel.movieListMonth3[indexPath.row]["title"]! as! String 9 case 3: cell.movieListText?.text = movieListModel.movieListMonth4[indexPath.row]["title"]! as! String 10 case 4: cell.movieListText?.text = movieListModel.movieListMonth5[indexPath.row]["title"]! as! String 11 case 5: cell.movieListText?.text = movieListModel.movieListMonth6[indexPath.row]["title"]! as! String 12 case 6: cell.movieListText?.text = movieListModel.movieListMonth7[indexPath.row]["title"]! as! String 13 case 7: cell.movieListText?.text = movieListModel.movieListMonth8[indexPath.row]["title"]! as! String 14 case 8: cell.movieListText?.text = movieListModel.movieListMonth9[indexPath.row]["title"]! as! String 15 case 9: cell.movieListText?.text = movieListModel.movieListMonth10[indexPath.row]["title"]! as! String 16 case 10: cell.movieListText?.text = movieListModel.movieListMonth11[indexPath.row]["title"]! as! String 17 case 11: cell.movieListText?.text = movieListModel.movieListMonth12[indexPath.row]["title"]! as! String 18 default: break 19 } 20 21 // Theater or Homeアイコンの表示/非表示 22 if movieListModel.movieListMonth1[indexPath.row]["watched_place"] as? String == "theater" { 23 cell.iconTheaterOrHome?.image = UIImage(named: "icon_theater") 24 } else if movieListModel.movieListMonth1[indexPath.row]["watched_place"] as? String == "home" { 25 cell.iconTheaterOrHome?.image = UIImage(named: "icon_house") 26 } else { 27 cell.iconTheaterOrHome.hidden = true 28 } 29 30 // もう1度見たいアイコンの表示/非表示 31 if movieListModel.movieListMonth1[indexPath.row]["once_again"] as? String == "yes" { 32 cell.iconHeart.image = UIImage(named: "icon_heart") 33 } else if movieListModel.movieListMonth1[indexPath.row]["once_again"] as? String == "no" { 34 cell.iconHeart.hidden = true 35 } else { 36 cell.iconHeart.hidden = true 37 } 38 39 // separatorの左の空きをなくす 40 cell.preservesSuperviewLayoutMargins = false 41 cell.separatorInset = UIEdgeInsetsZero 42 cell.layoutMargins = UIEdgeInsetsZero 43 44 return cell 45 }
###補足情報(言語/FW/ツール等のバージョンなど)
より詳細な情報
コード内のコメント「Theater or Homeアイコンの表示/非表示」「もう1度見たいアイコンの表示/非表示」でimageView内の画像を表示させたり、非表示にさせたりしているのですが、TableViewをスクロールして、また上まで戻ると、最初表示されていたimageView内の画像が消えてしまいます。おそらくCellの再描画が原因ではないかと思っているのですが、どうやって解決すればよろしいでしょうか。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2016/08/14 05:18