SHARE
TWEET

Untitled

a guest Sep 11th, 2019 79 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. override func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
  2.     .
  3.     .
  4.     .
  5.    
  6.     //按下cell後的動作--> 將畫面切換到navigation controller
  7.         cell.buttonPressedAction = {
  8.             //performSeuge在傳送之前會先觸發prepare,performSegue是透過sender傳送資料
  9.             self.performSegue(withIdentifier: "idFirstSegue", sender: indexPath.row)
  10.         }
  11.  return cell
  12.  }
  13.  
  14.      //使用prepare傳遞資料到SelectedPhotoViewController
  15.     override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
  16.  
  17.         //使用此方法將資料穿過navigation controller送到 SelectedPhotoViewController
  18.         let navigationController = segue.destination as! SelectedNavigationController
  19.         //first代表在collection中的第一個東西(是root view controller,viewController是一個陣列)
  20.         //順帶一提,back view controller是在陣列的 n-2,top controller在 n-1,n為array中item的數量
  21.         let SelectedPhotoController = navigationController.viewControllers.first as? SelectedPhotoViewController
  22.        
  23.         //由 performSegue 觸發的 prepare function 後面的 sender 代表要傳遞的東西
  24.         //而若是直接從 storyboard 點選所觸發的 segue ,這邊的 sender 則是代表點選的元件
  25.        
  26.     }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top