我有一个tableView,用户可以在其中滑动(左)以删除数据条目。如果用户向左滑动,然后点击删除(或"取消"右),用户点击unwindSegueButton,AppDelegate中的应用程序崩溃。
崩溃发生在我正在倒带的viewController中。它完全加载,但随后崩溃。如果用户提交删除或" unswipe"首先,没有崩溃......
我该如何避免这种情况?我可以在准备翻译中做一些撤消左侧滑动吗?
func tableView(tableView: UITableView, canEditRowAtIndexPath indexPath: NSIndexPath) -> Bool {
let source = objectSample[indexPath.row].source.name
return source == "MyApp"
}
func tableView(tableView: UITableView, commitEditingStyle editingStyle: UITableViewCellEditingStyle, forRowAtIndexPath indexPath: NSIndexPath) {
let source = objectSample[indexPath.row].source.name
//println(objectSample[indexPath.row].UUID)
if (editingStyle == UITableViewCellEditingStyle.Delete) && (source == "MyApp") {
let UUIDtoDelete = objectSample[indexPath.row].UUID
println("Deleted entry: \(source)")
deleteUUIDobject(UUIDtoDelete)
objectSample.removeAtIndex(indexPath.row)
tableView.deleteRowsAtIndexPaths([indexPath], withRowAnimation: UITableViewRowAnimation.Automatic)
}else {
println("Not allowed to delete, source: \(source)")
}
}
的AppDelegate
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
let isOnboarded = NSUserDefaults.standardUserDefaults().boolForKey("Onboarded")
let storyboard = UIStoryboard(name: "Main", bundle: nil)
// instantiate your desired ViewController
let dashboardViewController = storyboard.instantiateViewControllerWithIdentifier("DashboardVC") as! UIViewController
let onboardingViewControllerOne = storyboard.instantiateViewControllerWithIdentifier("OnboardingVCOne") as! UIViewController
let navigationController = storyboard.instantiateViewControllerWithIdentifier("NavigationController") as! UINavigationController
if (isOnboarded) {
window!.rootViewController = navigationController
}else{
window!.rootViewController = onboardingViewControllerOne
}
return true
}
答案 0 :(得分:0)
我通过添加下面的代码解决了崩溃,但我希望我知道为什么崩溃发生在第一位。
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
self.tableView.setEditing(false, animated: true)
}