Advertisement
axxe16

Segue tabella dettaglio

Oct 17th, 2018
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Swift 1.43 KB | None | 0 0
  1.  override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
  2.        
  3.         // se il segue che è scattato è quello chiamato detail...
  4.         if segue.identifier == "detail" {
  5.            
  6.             // prendiamo possesso del controller che sta per aprirsi
  7.             let viewController = segue.destination as! Dettaglio
  8.            
  9.             // capiamo che cella è stata toccata dall'utente (ci serve il numero per estrare la var giusta dall'array)
  10.             // e lo facciamo nel classico test "if let variabile" perchè l'operazione potrebbe fallire (e l'App andrebbe in crash)
  11.             if let indexPath = tableView.indexPathForSelectedRow {
  12.                
  13.                 // passiamo al controller l'App da mostrare
  14.                 // prendendola direttamente dall'array che sta in DownloadManager
  15.                 viewController.app = DownloadManager.shared.localArra[indexPath.row]
  16.                
  17.                 // estraiamo la cella selezionata dalla table
  18.                 if let cella = self.tableView.cellForRow(at: indexPath) as? TableViewCell {
  19.                    
  20.                     // passiamo la foto al dettaglio
  21.                     viewController.scuolaImage = cella.immagine.image
  22.                 }
  23.                 // deselezionamo a codice la cella (se no, da fastidio all'animazione)
  24.                 self.tableView.deselectRow(at: indexPath, animated:true)
  25.             }
  26.         }
  27.        
  28.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement