无法使用推送 segue 在视图控制器之间传递 UIImageView
Cannot pass UIImageView between view controllers using a push segue
我正在尝试使用 Push Segue 将 UIImageView 从主视图控制器传递到详细视图控制器。 Master View Controller 上的所有内容都可以正常加载,我已经使用 Master View Controller 上的 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.
}
}
如果能帮助确定问题所在,我们将不胜感激。
尝试在 prepareForSegue:
内部进行更改,而不是使用:
playlistDetailController?.image = UIImage(named: coverImage)
使用:
playlistDetailController.image = coverImage.image
祝你好运!
我正在尝试使用 Push Segue 将 UIImageView 从主视图控制器传递到详细视图控制器。 Master View Controller 上的所有内容都可以正常加载,我已经使用 Master View Controller 上的 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.
}
}
如果能帮助确定问题所在,我们将不胜感激。
尝试在 prepareForSegue:
内部进行更改,而不是使用:
playlistDetailController?.image = UIImage(named: coverImage)
使用:
playlistDetailController.image = coverImage.image
祝你好运!