swift 如何将图像传递给可点击的表格视图单元格?
swift how to pass image to a clickable tableview cell?
我正在制作一个用户可以按下并从按下的单元格中获取更多详细信息的表格视图。但是,我在如何让 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 弱变量 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
,正确的设置方法是什么
感谢您的帮助!
在您的代码中获取此类图像。
@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")
我正在制作一个用户可以按下并从按下的单元格中获取更多详细信息的表格视图。但是,我在如何让 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 弱变量 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
,正确的设置方法是什么感谢您的帮助!
在您的代码中获取此类图像。
@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")