我正在制作一个桌面视图,用户可以按下并从按下的单元格中获取更详细的信息。但是,我在如何使UIimage工作方面遇到了一些麻烦。
我的代码如下:
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 weak 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 :(得分: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")