简体   繁体   中英

Swift SIGABRT Error (no faulty connections)

Bear with me please I am completely new to Swift.I am trying to segue to another UIViewController by selecting a cell from ClassList UITableView, but no matter what I try I always seem to get the same Sigabrt error. I did a lot of research and most of what I heard said that it came from leftover/unused connections on the main storyboard but I checked and I have none. All I'm getting for my error is lldb and I can't understand the objective c output when I put in bt. I will post the error output if necessary but for now this is my code (sorry its so long I didn't want to risk leaving something important out)

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

This is where I keep getting there error

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

    }

 }  
}

UPDATE

Now when I load this code upon clicking on a cell nothing happens, it is just highlighted and no segue occurs. here is the code

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

    }

}

Change your sender Indexpath to nill

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

By the way there are some unused variables in prepareForSegue, This will not cause any errors but there is the variable that is not use, so I would like to suggest :-

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM