ios - Swift SIGABRT 错误(无错误连接)

标签 ios swift sigabrt

请耐心等待,我对 Swift 完全陌生。我试图通过从 ClassList UITableView 中选择一个单元格来连接到另一个 UIViewController,但无论我尝试什么,我似乎总是遇到相同的 Sigabrt 错误。我做了很多研究,我听到的大部分内容都说它来自主 Storyboard上剩余/未使用的连接,但我检查了,但我没有。我得到的所有错误都是 lldb,当我输入 bt 时我无法理解 objective-c 输出。如果有必要,我会发布错误输出,但现在这是我的代码(抱歉,它太长了,我不想冒险遗漏一些重要的东西)

import UIKit
import Firebase
import FirebaseDatabase

var classes = [String]()
var CurrentClass = ""

class TeacherHomeScreen : UIViewController, UITableViewDelegate, UITableViewDataSource{


@IBOutlet var ClassList: UITableView!

override func viewDidLoad() {
    super.viewDidLoad()
    if NSUserDefaults.standardUserDefaults().objectForKey(CurrentUser) != nil{
        classes = NSUserDefaults.standardUserDefaults().objectForKey((FIRAuth.auth()?.currentUser?.email)!)! as! [String]
    }
    else{
        classes = [""]
    }
    viewDidAppear(true)
}

func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
    self.performSegueWithIdentifier("SelectedClassSegue", sender: indexPath)
}

func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int{
    return classes.count
}

func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell{
    let ClassCell = tableView.dequeueReusableCellWithIdentifier("ClassCell", forIndexPath: indexPath)         
    ClassCell.textLabel?.text = classes[indexPath.row]
   // ClassCell.ProjectButton.tag = indexPath.row
    return ClassCell
}

override func viewDidAppear(animated: Bool) {
    ClassList.reloadData()
}

func tableView(tableView: UITableView, commitEditingStyle editingStyle: UITableViewCellEditingStyle, forRowAtIndexPath indexPath: NSIndexPath){
    if editingStyle == UITableViewCellEditingStyle.Delete{
        classes.removeAtIndex(indexPath.row)
        NSUserDefaults.standardUserDefaults().setObject(classes, forKey: CurrentUser)
        ClassList.reloadData()
    }
}

override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
}

这是我不断遇到错误的地方

override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
    if segue.identifier ==  "TeacherLogOut"{
        CurrentUser = ""
        try! FIRAuth.auth()!.signOut()
    }
    if segue.identifier ==  "SelectedClassSegue"{
        _ = segue.destinationViewController as! SelectedClass

    }

 }  
}

更新

现在,当我在单击一个单元格时加载此代码时,什么也没有发生,它只是突出显示并且没有发生 segue。这是代码

import Foundation

import UIKit
import Firebase
import FirebaseDatabase


var CurrentClass = ""

var classes = [String]()

class TeacherHomeScreen : UIViewController, UITableViewDelegate, UITableViewDataSource{


@IBOutlet var ClassList: UITableView!

override func viewDidLoad() {
    super.viewDidLoad()

    if NSUserDefaults.standardUserDefaults().objectForKey(CurrentUser) != nil{

        classes = NSUserDefaults.standardUserDefaults().objectForKey((FIRAuth.auth()?.currentUser?.email)!)! as! [String]
    }
    else{
        classes = [""]
    }
}

func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int{

    return classes.count
}

func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell{

    let ClassCell = tableView.dequeueReusableCellWithIdentifier("ClassCell", forIndexPath: indexPath)         
    ClassCell.textLabel?.text = classes[indexPath.row]

   // ClassCell.ProjectButton.tag = indexPath.row

    return ClassCell
    }
override func viewDidAppear(animated: Bool) {
    ClassList.reloadData()
}

func tableView(tableView: UITableView, commitEditingStyle editingStyle: UITableViewCellEditingStyle, forRowAtIndexPath indexPath: NSIndexPath){

    if editingStyle == UITableViewCellEditingStyle.Delete{

        classes.removeAtIndex(indexPath.row)

        NSUserDefaults.standardUserDefaults().setObject(classes, forKey: CurrentUser)

        ClassList.reloadData()

    }

}

override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
}

override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
    if segue.identifier ==  "TeacherLogOut"{

        CurrentUser = ""
        try! FIRAuth.auth()!.signOut()
    }
   // if segue.identifier ==  "SelectedClassSegue"{

       // _ = segue.destinationViewController as! SelectedClass

    }

}

最佳答案

将您的发件人索引路径更改为空

func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
    self.performSegueWithIdentifier("SelectedClassSegue", sender: nil)
}

顺便说一句,prepareForSegue 中有一些未使用的变量,这不会导致任何错误,但有未使用的变量,所以我想建议:-

  override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
       if segue.identifier ==  "TeacherLogOut"{
          CurrentUser = ""
          try! FIRAuth.auth()!.signOut()
       }
      if segue.identifier ==  "SelectedClassSegue"{
        //_ = segue.destinationViewController as! SelectedClass 
        //This variable is unused , so no need to put this line
      }
 }

关于ios - Swift SIGABRT 错误(无错误连接),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37935037/

相关文章:

ios - iOS 内存对齐错误

ios - swift: 在调试中打印\r 字符

json - 如何在将 String 映射到 Int 或 String 的 Swift 中保存字典的 JSON 数组?

iOS 异常回溯 - 应用程序条目未符号化

xcode - 阻止 Xcode 切换到 SIGABRT 上的应用委托(delegate)

android - Twilio 是否足以进行国际短信验证?

iphone - 如何检测推送 subview 后 UIviewcontroller 何时再次激活?

ios - 自定义 UIControl 不适用于 UITapGestureRecognizer

ios - 如何在 UISearchController 中自定义 searchBar?

ios - xcode 6.1 (Swift) 中的 SIGABRT 运行时错误