“应用程序试图以模态方式呈现活动控制器”iOS8 - 当我想在注销时显示AlertView
问题描述:
那么,我真的是一个初学者,在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
答
试过这个,我发现了一个解决方案,通过使用SWReveal创建菜单栏的普通迅速文件,而不是创建一个可可触摸文件。所以它现在将会是import Foundation
而不是import UIKit
。菜单栏滑块有问题,因为当它是可可触摸时,滑块被视为控制器,并且AlertView是另一个要呈现的视图控制器。