2014-12-06 10 views
5

Visualizzo un controller UIAlert durante il download dell'immagine. Quando il download è finito, voglio spingere un controller di visualizzazione. Ho un errore nella console, perché non respingere il controller avviso:Come ignorare un UIAlertController senza azioni in SWIFT?

pushViewController:animated: called on <UINavigationController 0x7fb190c6ee00> while an existing transition or presentation is occurring; the navigation stack will not be updated. 

A mio controller della vista principale, quando il download è terminato, spingo altro punto di vista:

override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) { 

    //.... 

    var alert = UIAlertController(title: "Alert", message: text, preferredStyle: UIAlertControllerStyle.Alert) 
    self.presentViewController(alert, animated: true, completion: nil) 


    dispatch_async(dispatch_get_main_queue(), { 
     if let cellToUpdate = tableView.cellForRowAtIndexPath(indexPath) { 
       self.performSegueWithIdentifier("postview", sender: self) 

     } 
    }) 
} 

I ingegno provato dismissViewControllerAnimated ma ho esattamente lo stesso errore:

dispatch_async(dispatch_get_main_queue(), { 
      if let cellToUpdate = tableView.cellForRowAtIndexPath(indexPath) { 
        alert.dismissViewControllerAnimated(true, completion: nil) 
        self.performSegueWithIdentifier("postview", sender: self) 

      } 
     }) 

risposta

9

non si dovrebbe chiamare performSegueWithIdentifier prima che il precedente controller di vista è stato respinto. Per il tempo correttamente, farlo dal gestore di completamento:

dispatch_async(dispatch_get_main_queue(), { 
    if let cellToUpdate = tableView.cellForRowAtIndexPath(indexPath) { 
     alert.dismissViewControllerAnimated(true, completion: { 
      self.performSegueWithIdentifier("postview", sender: self) 
     }) 
    } 
}) 

Ora la chiamata per eseguire segue non sarebbe iniziare fino a quando il licenziamento è finita, impedendo l'errore che si vede.

+0

Funziona! Grazie ! – cmii

+0

Anche io sto avendo lo stesso problema, @ dasblinkenlight.Puoi aiutarmi? Ecco il mio link: http://stackoverflow.com/questions/30840235/console-warning-in-my-custom-alert-controller-which- detto-che-era-tentativo-to-Prese –

Problemi correlati