无法使用push segue在视图控制器之间传递UIImageView

时间:2015-07-11 23:44:48

标签: uiimageview push segue

我正在尝试使用Push Segue将UIImageView从主视图控制器传递到详细视图控制器。主视图控制器上的所有内容都可以正常加载,我使用主视图控制器上的UIImageView创建了一个push segue。这是我的主视图控制器 -

class TrackMasterViewController: UIViewController {

    @IBOutlet weak var artistName: UILabel!

    @IBOutlet weak var albumName: UILabel!

    @IBOutlet weak var numberOfTracks: UILabel!

    @IBOutlet weak var coverImage: UIImageView!

    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.

        let firstRandomNumber = calculateRandomNumber()

        artistName.text = Track(index: firstRandomNumber).artist
        albumName.text = Track(index: firstRandomNumber).album
        coverImage.image = Track(index: firstRandomNumber).image
        numberOfTracks.text = Track(index: firstRandomNumber).track

    }

这是传递的封面图像。这是我的segue函数 -

override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
        if segue.identifier == "trackSegue" {
            let playlistDetailController = segue.destinationViewController as? TrackDetailViewController
            playlistDetailController?.image = UIImage(named: coverImage)

        }
    }

在我的详细视图控制器中,我有以下内容:

class TrackDetailViewController: UIViewController {

    @IBOutlet weak var albumCover: UIImageView!

    var image:UIImage? = nil

    override func viewDidLoad() {
        super.viewDidLoad()

        albumCover.image = image

        // Do any additional setup after loading the view.



    }

}

任何有助于确定问题的帮助将不胜感激。

1 个答案:

答案 0 :(得分:0)

尝试更改prepareForSegue:内部,而不是使用:

playlistDetailController?.image = UIImage(named: coverImage)

使用:

playlistDetailController.image = coverImage.image
祝你好运!