在 Swift 内将图像视图从一个视图控制器传输到另一个视图控制器
Transfer Image View from one View Controller to another in Swift
我今天下午在 Xcode 一直在摸索相机应用程序,但遇到了障碍。我希望使用 prepareForSegue 方法将图像视图从相机传输到 ViewController。使用相机 class 中的其余代码,我可以成功地将图像显示到故事板上的图像视图,所以这不是问题所在。问题是将它显示到主 ViewController 中的图像视图。我在 Storyboard 中正确连接了所有内容。感谢您的帮助!
第一个视图控制器:
class ViewController: UIViewController {
@IBOutlet weak var photoViewData: UIImageView!
}
第二个视图控制器:
class Camera: UIViewController, UIImagePickerControllerDelegate, UINavigationControllerDelegate {
@IBOutlet var imageView:UIImageView!
@IBOutlet var takePictureButton:UIButton!
var moviePlayerController: MPMoviePlayerController?
var image:UIImage?
var movieURL: NSURL?
var lastChosenMediaType: String?
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
var destViewController: ViewController = segue.destinationViewController as ViewController
destViewController.photoViewData = imageView
}
我认为在控制器之间传递 UIImage 会更好。
class ViewController: UIViewController
{
strong var photo: UIImage!
override function viewDidLoad()
{
if(self.photo)
self.imageView.image = photo;
}
}
class Camera: UIViewController, UIImagePickerControllerDelegate, UINavigationControllerDelegate
{
@IBOutlet var imageView:UIImageView!
@IBOutlet var takePictureButton:UIButton!
var moviePlayerController: MPMoviePlayerController?
var image:UIImage?
var movieURL: NSURL?
var lastChosenMediaType: String?
override func prepareForSegue(segue: UIStoryboardSegue, sender:AnyObject?)
{
var destViewController: ViewController = segue.destinationViewController as ViewController
destViewController.photo = imageView.image
}
我今天下午在 Xcode 一直在摸索相机应用程序,但遇到了障碍。我希望使用 prepareForSegue 方法将图像视图从相机传输到 ViewController。使用相机 class 中的其余代码,我可以成功地将图像显示到故事板上的图像视图,所以这不是问题所在。问题是将它显示到主 ViewController 中的图像视图。我在 Storyboard 中正确连接了所有内容。感谢您的帮助!
第一个视图控制器:
class ViewController: UIViewController {
@IBOutlet weak var photoViewData: UIImageView!
}
第二个视图控制器:
class Camera: UIViewController, UIImagePickerControllerDelegate, UINavigationControllerDelegate {
@IBOutlet var imageView:UIImageView!
@IBOutlet var takePictureButton:UIButton!
var moviePlayerController: MPMoviePlayerController?
var image:UIImage?
var movieURL: NSURL?
var lastChosenMediaType: String?
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
var destViewController: ViewController = segue.destinationViewController as ViewController
destViewController.photoViewData = imageView
}
我认为在控制器之间传递 UIImage 会更好。
class ViewController: UIViewController
{
strong var photo: UIImage!
override function viewDidLoad()
{
if(self.photo)
self.imageView.image = photo;
}
}
class Camera: UIViewController, UIImagePickerControllerDelegate, UINavigationControllerDelegate
{
@IBOutlet var imageView:UIImageView!
@IBOutlet var takePictureButton:UIButton!
var moviePlayerController: MPMoviePlayerController?
var image:UIImage?
var movieURL: NSURL?
var lastChosenMediaType: String?
override func prepareForSegue(segue: UIStoryboardSegue, sender:AnyObject?)
{
var destViewController: ViewController = segue.destinationViewController as ViewController
destViewController.photo = imageView.image
}