・現在学習中の課題で、スライドショーアプリ作成におけるsegueによる画像の遷移元⇆遷移先のコードを書く必要があります。
※画像を自動再生するスライドショーアプリで、画像をタップすると遷移先の画面で拡大されたものが表示される仕様。
・xやyに数を代入させる計算ではsegueを経験しているのですが、画像のやりとりとなるとどのようにコードを書いていいのかわからず、色々な文字列を打って試しているのですが、何を打っても赤いアラートが出て困ってしまっています。
※下記コードで、遷移元(ViewController)のsegueの下のletから始まる部分の、遷移先に画像を送るコードと、遷移先(CloseUpViewController)で受け取るためのコードがわからずに困っています。
アドバイスをよろしくお願いします。
遷移元
import UIKit class ViewController: UIViewController { let image = ["画像0","画像1","画像2","画像3","画像4","画像5","画像6","画像7"] var timer:Timer? var counter:Int = 0 override func viewDidLoad() { super.viewDidLoad() // Do any additional setup after loading the view, typically from a nib. } @IBOutlet weak var buttonPlayPause: UIButton! @IBOutlet weak var buttonBack: UIButton! @IBOutlet weak var buttonNext: UIButton! //再生ボタンを押した時のメソッド @IBAction func buttonPlayPause(_ sender: Any) { if self.timer != nil { buttonBack.setTitleColor(UIColor.darkGray, for: .normal) buttonNext.setTitleColor(UIColor.darkGray, for: .normal) buttonPlayPause.setTitle("Play", for: UIControlState.normal) timer?.invalidate() timer = nil } else { buttonPlayPause.setTitle("Pause", for: UIControlState.normal) timer = Timer.scheduledTimer(timeInterval: 2.0, target: self, selector: (#selector(play)), userInfo: nil, repeats: true) buttonBack.isEnabled = false //戻るボタンタップ不可 buttonBack.setTitleColor(UIColor.lightGray, for: .normal) buttonNext.isEnabled = false //次へボタンタップ不可 buttonNext.setTitleColor(UIColor.lightGray, for: .normal) } } //戻るボタンを押した時のメソッド @IBAction func buttonBack(_ sender: Any) { counter = counter - 1 //現在用意している画像が8枚なので、カウンターが-8より小さくなったら0になる if (counter < -7) { counter = 0 } imageView.image = UIImage(named:image[counter]) } //進むボタンを押した時のメソッド @IBAction func buttonNext(_ sender: Any) { //カウンターに1足して次の画像を表示させる counter = counter + 1 //現在用意している画像は8枚なので、カウンターが8より大きくなったら0になる if ( counter > 7 ) { counter = 0 } imageView.image = UIImage(named:image[counter]) } @IBOutlet weak var imageView: UIImageView! @IBAction func closeUp(_ sender: UIButton) { } override func prepare(for segue: UIStoryboardSegue, sender: Any?) { let closeUpViewController:CloseUpViewController = segue.destination as! CloseUpViewController closeUpViewController.imageView = self.image } override func didReceiveMemoryWarning() { super.didReceiveMemoryWarning() // Dispose of any resources that can be recreated.
遷移先
import UIKit class CloseUpViewController: UIViewController { @IBOutlet weak var imageView: UIImageView! var Image = UIImage() //受け取るためのプロパティ override func viewDidLoad() { super.viewDidLoad() // Do any additional setup after loading the view. } override func didReceiveMemoryWarning() { super.didReceiveMemoryWarning() // Dispose of any resources that can be recreated. }
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2017/03/03 14:23