【问题标题】:Swift SIGABRT Error (no faulty connections)Swift SIGABRT 错误(没有错误连接)
【发布时间】:2016-06-21 03:23:20
【问题描述】:

请耐心等待我对 Swift 完全陌生。我试图通过从 ClassList UITableView 中选择一个单元格来切换到另一个 UIViewController,但无论我尝试什么,我似乎总是遇到相同的 Sigabrt 错误。我做了很多研究,我听到的大部分内容都说它来自主情节提要上剩余/未使用的连接,但我检查了,我没有。我得到的所有错误都是 lldb,当我输入 bt 时,我无法理解目标 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

    }

 }  
}

更新

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

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

    }

}

【问题讨论】:

    标签: ios swift sigabrt


    【解决方案1】:

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

    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
          }
     }
    

    【讨论】:

    • 这似乎已经将 SIGABRT 错误转移到了它通常所在的应用程序委托。我为异常设置了断点,问题似乎源于这部分输出......至少从我能说的来看。有任何想法吗???帧 #1: 0x0000000101a94d3d CoreFoundation`-[NSObject(NSObject) doesNotRecognizeSelector:] + 205
    • 请显示完整的错误以及您在哪里得到错误,更新您的问题
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-02-28
    • 1970-01-01
    • 2018-05-21
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多