0

ええと、私は本当にSwift 2の初心者で、エラーが発生していますpresentViewController。これは、ログアウトする前の警告ビューです. しかし、アクティブなコントローラーをモーダルに提示しようとするアプリケーションを受け取りました。さて、メニューバーを保持するSWRevealViewControllerandMenuBarTableViewControllerクラスを使用したメニューバーがあります。Logoutボタンはメニューバーの最後の選択にあり、すべてのメニューをブラウズしていますが、正常に動作しますが、Logout 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)
         }
       }
    }



}

他のView ControllerでAlert View Controllerを何度も実行しているため、何がコードをクラッシュさせ、この種の例外を受け取ったのかわかりません。しかし、これを試したのはこれが初めてですMenuBarTableViewController

4

1 に答える 1

0

ココアタッチファイルを作成するのではなく、SWRevealを使用してメニューバー用のプレーンなswiftファイルを作成することで、これに対する解決策を見つけました。だから今import Foundationではなくimport UIKit。ココア タッチの場合、スライダーがコントローラーと見なされ、AlertView が表示される別のビュー コントローラーであるため、メニュー バー スライダーに問題があります。

于 2016-09-28T06:36:46.600 に答える