2016-09-27 45 views
0

那麼,我真的是一個初學者,在swift 2中我有一個錯誤presentViewController,這只是一個註銷之前的警報視圖。但是我收到一個應用程序,試圖以模態方式呈現主動控制器。那麼我有一個菜單欄,使用SWRevealViewControllerMenuBarTableViewController類保存菜單欄。 Logout按鈕位於菜單欄的最後一個選項上,我正在瀏覽每個菜單並且它工作正常,但這Logout AlertView使它崩潰並且出現該錯誤。這是代碼。「應用程序試圖以模態方式呈現活動控制器」iOS8 - 當我想在註銷時顯示AlertView

class MenuBarTableViewController: UITableViewController { 
    private struct PMText { 
     static let logoutBody = "Are you sure you want to log out?" 
    } 

    var alert = UIAlertController(title: "Logout", message: PMText.logoutBody, preferredStyle: UIAlertControllerStyle.Alert) 

    override func viewDidLoad() { 
     super.viewDidLoad() 

     alert.addAction(UIAlertAction(
      title: "No", 
      style: UIAlertActionStyle.Cancel) 
     { (action: UIAlertAction) -> Void in 
      //do nothing just to close the alertView 
      } 
     ) 

     alert.addAction(UIAlertAction(
      title: "Yes", 
      style: UIAlertActionStyle.Default) 
     { (action: UIAlertAction) -> Void in 
      self.performSegueWithIdentifier("log out", sender: nil) 
      } 
     ) 

     tableView.separatorColor = UIColor.clearColor() 
    } 

    override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) { 
     for index in 0..<tableView.numberOfRowsInSection(indexPath.section) { 
     let cellIndexPath = NSIndexPath(forRow: index, inSection: indexPath.section) 
     let cell = tableView.cellForRowAtIndexPath(cellIndexPath)! 
     if index == indexPath.row { 
      cell.backgroundColor = UIColor(red: 254/255, green: 255/255, blue: 197/255, alpha: 1) 
     } else { 
      cell.backgroundColor = UIColor.whiteColor() 
     } 


     if (indexPath.row == 6) { 
      presentViewController(alert, animated: true, completion: nil) 
     } 
     } 
    } 



} 

好吧,我不知道是什麼讓我的代碼崩潰,因爲我正在做的警報視圖控制器有很多次我在其他視圖控制器接收到這種異常。但是,這是我第一次在MenuBarTableViewController

回答

0

試過這個,我發現了一個解決方案,通過使用SWReveal創建菜單欄的普通迅速文件,而不是創建一個可可觸摸文件。所以它現在將會是import Foundation而不是import UIKit。菜單欄滑塊有問題,因爲當它是可可觸摸時,滑塊被視爲控制器,並且AlertView是另一個要呈現的視圖控制器。

相關問題