私は、プログラムでCollectionViewを作成し、それに画像を渡しました。今、各画像ビューをタップするには、次のそれぞれのView Controllerを開く必要があります。私はSwiftの初心者で、Swift 3でこの解決策を見つけることができませんでした。 4番目の 'todolistbutton'画像ビューでそれをやろうとしましたが、エラーが表示されました。誰でもSwift 3で私を助けてくれる? 私のコードは次のとおりです。コレクションビューセルを新しいコントローラにリンクする
import UIKit
class MeBottomViewController: UIViewController, UICollectionViewDataSource, UICollectionViewDelegate {
@IBOutlet weak var collectionView: UICollectionView!
let imageArray = [UIImage(named: "guidebutton"), UIImage(named: "mybellybutton"), UIImage(named: "appointmentbutton"), UIImage(named: "todolistbutton"), UIImage(named: "duedatebutton"), UIImage(named: "myweightbutton")]
override func viewDidLoad() {
super.viewDidLoad()
let tap = UITapGestureRecognizer(target: self, action: #selector(tappedme))
imageArray[3].addGestureRecognizer(tap) // Error: Value of type 'UIImage?' has no member 'addGestureRecognizer'
imageArray[3].userInteractionEnabled = true // Error: Value of type 'UIImage?' has no member 'userInteractionEnabled'
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return 6
}
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cells = collectionView.dequeueReusableCell(withReuseIdentifier: "cells", for: indexPath as IndexPath) as! SecondCollectionViewCell
cells.imageView?.image = self.imageArray[indexPath.row]
return cells
}
func tappedme() {
let secondViewController = self.storyboard?.instantiateViewController(withIdentifier: "ToDoTableViewController") as! ToDoTableViewController
self.navigationController?.pushViewController(secondViewController, animated: true)
}
}
あなたは 'UIImageView'に' UITapGestureRecognizer'を追加したいと思いますが、あなたはそれらを 'UIImage'に追加しようとしています... –
私はそこにすべてのコードを与えているので、あなたは答えを凝ってくれますか?私はそれぞれのimageviewsをタップして別々にビューコントローラを開く必要があります。私は迅速に新しいです。 Plzzz ....ありがとうございます。 –