2016-07-15 65 views
0

我正在製作一個表格,用戶可以按下並從按下的單元格中獲取更詳細的信息。不過,我在如何使UIimage發揮作用方面遇到了一些麻煩。swift如何將圖像傳遞給可點擊的tableview單元格?

我的代碼如下:

let shotMatchSegue = "ShowMatchSegue" 
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) { 
    if segue.identifier == shotMatchSegue, 
    let destination = segue.destinationViewController as? MatchViewController, 
    matchIndex = recentMatchesTableView.indexPathForSelectedRow?.row 
    { 
     destination.matchChampionImage = UIImage(named: "\(championsPlayed[matchIndex])_Splash_Tile_0") 
     destination.matchType = gameType[matchIndex] 
    } 
} 

我MatchViewController,我有以下幾點:

@IBOutlet弱VAR gameMatchChampionIcon:UIImageView的!

@IBOutlet weak var gameMatchType: UILabel! 
var matchType = String() 
var championIcon = String() 
override func viewWillAppear(animated: Bool) { 
    gameMatchChampionIcon.image = UIImage() 
    gameMatchType.text = matchType 
} 

我能想象這是最有可能的,我建立了我的gameMatchChampionIcon.image =的UIImage()錯誤的情況。所以我想知道什麼是正確的方式來設置,如果我想傳遞圖像到UIimage

感謝您的幫助!

回答

0

在你的代碼中獲取這種類型的圖像。

@IBOutlet weak var gameMatchType: UILabel! 
@IBOutlet weak var gameMatchChampionIcon: UIImageView? 
    var photo: UIImage? { 
     didSet { 
      gameMatchChampionIcon?.image = photo 
     } 
    } 
var matchType = String() 
var championIcon = String() 
override func viewWillAppear(animated: Bool) { 
    gameMatchChampionIcon?.image = photo 
    gameMatchType.text = matchType 
} 

,並在SEGUE通過你的形象照片可變

destination.photo = UIImage(named: "\(championsPlayed[matchIndex])_Splash_Tile_0") 
+0

YAY它的作品!謝謝你,朋友! – user3175707

相關問題