【问题标题】:swift how to pass image to a clickable tableview cell?swift如何将图像传递给可点击的tableview单元格?
【发布时间】:2016-07-15 04:38:38
【问题描述】:

我正在制作一个表格视图,用户可以按下它并从按下的单元格中获取更多详细信息。但是,我在如何让 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,正确的设置方法是什么

感谢您的帮助!

【问题讨论】:

    标签: swift2 uiimage segue tableviewcell


    【解决方案1】:

    在您的代码中获取这种类型的图像。

    @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 中传递给 photo 变量

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-11-07
      • 1970-01-01
      • 2021-08-30
      • 2012-06-26
      • 2018-04-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多