私は故郷のレストランを表示し、メニュー、開店時間、住所を与えるためにこのアプリケーションを構築しています。私はこれは私がコレクションビュー機能で#selectorに渡す機能であるコレクションビューにレストランについての情報を表示するにはセレクタとローカル機能
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "cell", for: indexPath) as! RestaurantCollectionViewCell
cell.addressLabel.text = addressArray[indexPath.row]
cell.restaurantNameLabel.text = restaurantArray[indexPath.row]
cell.openingTimeLabel.text = openingTimeArray[indexPath.row]
cell.chosenRestaurantButton.addTarget(self, action: #selector(getProducts), for: .touchUpInside)
return cell
}
ここで、この機能を持っています。つまり、getProducts関数のコレクションビュー関数からインデックスパスが必要です。私は関数をネストできないので、ローカル関数についてのエラーがスローされます。どのように私はgetProducts関数でインデックスパスを取得することができますか?
func getProducts() {
let viewController = storyboard?.instantiateViewController(withIdentifier: "productsCollectionView") as! ProductsViewController
viewController.restaurantChosen = restaurantArray[indexPathVariable.row]
self.present(viewController, animated: true, completion: nil)
}
心うわー、それは動作します吹き飛ばさ。ありがとうございました。 – user3103854