那麼,我真的是一個初學者,在swift 2中我有一個錯誤presentViewController
,這只是一個註銷之前的警報視圖。但是我收到一個應用程序,試圖以模態方式呈現主動控制器。那麼我有一個菜單欄,使用SWRevealViewController
和MenuBarTableViewController
類保存菜單欄。 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