App crashes when table cell is selected Swift

I have tried to fix it but when I login on my app, it goes to a table view controller and when i click on a cell, it crashes with an error of 'terminating with uncaught exception of type NSException' , it says Signal Abort and I don't know why. Any help would be greatly appreciated thanks.

Link to project: https://www.dropbox.com/s/1d4d8opuxzpcuk4/TicketekApp.zip?dl=0

Code:

EventTableViewController (Source View Controller):

//  EventTableViewController.swift



import UIKit

class EventTableViewController: UITableViewController {
// MARK: Properties
var currentlySelectedIndex = 0
var events = [Event]()
var isAdmin: Bool = false
var currentUser: String = ""
override func viewDidLoad() {
    super.viewDidLoad()

    // Use the edit button item provided by the table view controller.
    if isAdmin == true {
    navigationItem.leftBarButtonItem = editButtonItem()
    }
    // Load any saved events, otherwise load sample data.
    if let savedEvents = loadEvents() {
        events += savedEvents
    } else {
        // Load the sample data.
        loadSampleEvents()
    }
}

func loadSampleEvents() {
    let photo1 = UIImage(named: "event1")!
    let event1 = Event(name: "ACDC", photo: photo1, rating: 4, price: 500.0, eventDescription: "Album", album: "Album1")!

    let photo2 = UIImage(named: "event2")!
    let event2 = Event(name: "Cold Play", photo: photo2, rating: 5, price: 500.0, eventDescription: "Album", album: "Album1")!

    let photo3 = UIImage(named: "event3")!
    let event3 = Event(name: "One Direction", photo: photo3, rating: 3, price: 500.0, eventDescription: "Album", album: "Album1")!

    events += [event1, event2, event3]
}

override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
    // Dispose of any resources that can be recreated.
}

// MARK: - Table view data source

override func numberOfSectionsInTableView(tableView: UITableView) -> Int {
    return 1
}

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

override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
    // Table view cells are reused and should be dequeued using a cell identifier.
    let cellIdentifier = "EventTableViewCell"
    let cell = tableView.dequeueReusableCellWithIdentifier(cellIdentifier, forIndexPath: indexPath) as! EventTableViewCell

    // Fetches the appropriate event for the data source layout.
    let event = events[indexPath.row]

    cell.nameLabel.text = event.name
    cell.photoImageView.image = event.photo
    cell.ratingControl.rating = event.rating
    cell.priceLabel.text = event.album

    return cell
}
override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {

    //Record the row selected
    currentlySelectedIndex = indexPath.row

    //check for your condition here something like
    if isAdmin {
        performSegueWithIdentifier("eventViewControllerSegue", sender: self)
    } else {
        performSegueWithIdentifier("userEventTableViewControllerSegue", sender: self)
    }
}

// Override to support conditional editing of the table view.
override func tableView(tableView: UITableView, canEditRowAtIndexPath indexPath: NSIndexPath) -> Bool {
    // Return false if you do not want item to be editable.
    return true
}


// Override to support editing the table view.
override func tableView(tableView: UITableView, commitEditingStyle editingStyle: UITableViewCellEditingStyle, forRowAtIndexPath indexPath: NSIndexPath) {
    if editingStyle == .Delete {
        // Delete the row from the data source
        events.removeAtIndex(indexPath.row)
        saveEvents()
        tableView.deleteRowsAtIndexPaths([indexPath], withRowAnimation: .Fade)
    } else if editingStyle == .Insert {
        // Create new instance of  class, add to the array, and add a new row to the table
    }
}


/*
// Override to support rearranging the table view.
override func tableView(tableView: UITableView, moveRowAtIndexPath fromIndexPath: NSIndexPath, toIndexPath: NSIndexPath) {

}
*/

/*
// Override to support conditional rearranging of the table view.
override func tableView(tableView: UITableView, canMoveRowAtIndexPath indexPath: NSIndexPath) -> Bool {
// Return false if you do not want the item to be re-orderable.
return true
}
*/


// MARK: - Navigation

// preparation before navigation
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
    if segue.identifier == "eventViewControllerSegue"  {
        let eventDetailViewController = segue.destinationViewController as! EventViewController
        //Get the associated event
        eventDetailViewController.event = events[currentlySelectedIndex]
    } else  if segue.identifier == "userEventViewControllerSegue"  {
        let eventDetailViewController = segue.destinationViewController as! UserEventViewController
        //Get the associated event
        eventDetailViewController.event = events[currentlySelectedIndex]
        if let destinationVC = segue.destinationViewController as? UserEventViewController {

            destinationVC.currentUser = currentUser
        }
    }
    else if segue.identifier == "AddItem" {
        print("Adding new event.")
    }
}

@IBAction func unwindToMealList(sender: UIStoryboardSegue) {
    if let sourceViewController = sender.sourceViewController as? EventViewController, event = sourceViewController.event {
        if let selectedIndexPath = tableView.indexPathForSelectedRow {
            // Update an existing event.
            events[selectedIndexPath.row] = event
            tableView.reloadRowsAtIndexPaths([selectedIndexPath], withRowAnimation: .None)
        } else {
            // Add a new event.
            let newIndexPath = NSIndexPath(forRow: events.count, inSection: 0)
            events.append(event)
            tableView.insertRowsAtIndexPaths([newIndexPath], withRowAnimation: .Bottom)
        }
        // Save the events.
        saveEvents()
    }
}

// MARK: NSCoding

func saveEvents() {
    let isSuccessfulSave = NSKeyedArchiver.archiveRootObject(events, toFile: Event.ArchiveURL.path!)
    if !isSuccessfulSave {
        print("Failed to save events...")
    }
}

func loadEvents() -> [Event]? {
    return NSKeyedUnarchiver.unarchiveObjectWithFile(Event.ArchiveURL.path!) as? [Event]
}
}

UserEventViewController (Destination View Controller if isAdmin is false):

//  EventViewController.swift



import UIKit

class UserEventViewController: UIViewController {
// MARK: Properties










@IBOutlet weak var eventDescriptionLabel: UITextView!

@IBOutlet weak var priceLabel: UILabel!

@IBOutlet weak var nameLabel: UILabel!

@IBOutlet weak var photoImageView: UIImageView!

@IBOutlet weak var albumNameLabel: UILabel!

@IBOutlet weak var myTitle: UINavigationItem!

@IBOutlet weak var ratingControl: RatingControl!

var event: Event?
var currentUser: String = ""

override func viewDidLoad() {
    super.viewDidLoad()



    // Set up views if editing an existing event.
    if let event = event {
        myTitle.title = event.name
        nameLabel.text   = event.name
        photoImageView.image = event.photo
        ratingControl.rating = event.rating
        eventDescriptionLabel.text = event.eventDescription
        albumNameLabel.text = event.album
        priceLabel.text = String(event.price)
    }
    }





override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
    // Dispose of any resources that can be recreated.
}
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
    if segue.identifier == "BuyTickets" {
        if let destinationVC = segue.destinationViewController as? seatsPickerViewController{
            destinationVC.price = event!.price
            destinationVC.name = event!.name
            destinationVC.album = event!.album
            destinationVC.photo = event!.photo
            destinationVC.currentUser = currentUser
        }
                }

}


}

EventViewController (Destination View Controller if isAdmin is true):

//  EventTableViewController.swift



import UIKit

class EventTableViewController: UITableViewController {
// MARK: Properties
var currentlySelectedIndex = 0
var events = [Event]()
var isAdmin: Bool = false
var currentUser: String = ""
override func viewDidLoad() {
    super.viewDidLoad()

    // Use the edit button item provided by the table view controller.
    if isAdmin == true {
    navigationItem.leftBarButtonItem = editButtonItem()
    }
    // Load any saved events, otherwise load sample data.
    if let savedEvents = loadEvents() {
        events += savedEvents
    } else {
        // Load the sample data.
        loadSampleEvents()
    }
}

func loadSampleEvents() {
    let photo1 = UIImage(named: "event1")!
    let event1 = Event(name: "ACDC", photo: photo1, rating: 4, price: 500.0, eventDescription: "Album", album: "Album1")!

    let photo2 = UIImage(named: "event2")!
    let event2 = Event(name: "Cold Play", photo: photo2, rating: 5, price: 500.0, eventDescription: "Album", album: "Album1")!

    let photo3 = UIImage(named: "event3")!
    let event3 = Event(name: "One Direction", photo: photo3, rating: 3, price: 500.0, eventDescription: "Album", album: "Album1")!

    events += [event1, event2, event3]
}

override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
    // Dispose of any resources that can be recreated.
}

// MARK: - Table view data source

override func numberOfSectionsInTableView(tableView: UITableView) -> Int {
    return 1
}

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

override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
    // Table view cells are reused and should be dequeued using a cell identifier.
    let cellIdentifier = "EventTableViewCell"
    let cell = tableView.dequeueReusableCellWithIdentifier(cellIdentifier, forIndexPath: indexPath) as! EventTableViewCell

    // Fetches the appropriate event for the data source layout.
    let event = events[indexPath.row]

    cell.nameLabel.text = event.name
    cell.photoImageView.image = event.photo
    cell.ratingControl.rating = event.rating
    cell.priceLabel.text = event.album

    return cell
}
override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {

    //Record the row selected
    currentlySelectedIndex = indexPath.row

    //check for your condition here something like
    if isAdmin {
        performSegueWithIdentifier("eventViewControllerSegue", sender: self)
    } else {
        performSegueWithIdentifier("userEventTableViewControllerSegue", sender: self)
    }
}

// Override to support conditional editing of the table view.
override func tableView(tableView: UITableView, canEditRowAtIndexPath indexPath: NSIndexPath) -> Bool {
    // Return false if you do not want item to be editable.
    return true
}


// Override to support editing the table view.
override func tableView(tableView: UITableView, commitEditingStyle editingStyle: UITableViewCellEditingStyle, forRowAtIndexPath indexPath: NSIndexPath) {
    if editingStyle == .Delete {
        // Delete the row from the data source
        events.removeAtIndex(indexPath.row)
        saveEvents()
        tableView.deleteRowsAtIndexPaths([indexPath], withRowAnimation: .Fade)
    } else if editingStyle == .Insert {
        // Create new instance of  class, add to the array, and add a new row to the table
    }
}


/*
// Override to support rearranging the table view.
override func tableView(tableView: UITableView, moveRowAtIndexPath fromIndexPath: NSIndexPath, toIndexPath: NSIndexPath) {

}
*/

/*
// Override to support conditional rearranging of the table view.
override func tableView(tableView: UITableView, canMoveRowAtIndexPath indexPath: NSIndexPath) -> Bool {
// Return false if you do not want the item to be re-orderable.
return true
}
*/


// MARK: - Navigation

// preparation before navigation
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
    if segue.identifier == "eventViewControllerSegue"  {
        let eventDetailViewController = segue.destinationViewController as! EventViewController
        //Get the associated event
        eventDetailViewController.event = events[currentlySelectedIndex]
    } else  if segue.identifier == "userEventViewControllerSegue"  {
        let eventDetailViewController = segue.destinationViewController as! UserEventViewController
        //Get the associated event
        eventDetailViewController.event = events[currentlySelectedIndex]
        if let destinationVC = segue.destinationViewController as? UserEventViewController {

            destinationVC.currentUser = currentUser
        }
    }
    else if segue.identifier == "AddItem" {
        print("Adding new event.")
    }
}

@IBAction func unwindToMealList(sender: UIStoryboardSegue) {
    if let sourceViewController = sender.sourceViewController as? EventViewController, event = sourceViewController.event {
        if let selectedIndexPath = tableView.indexPathForSelectedRow {
            // Update an existing event.
            events[selectedIndexPath.row] = event
            tableView.reloadRowsAtIndexPaths([selectedIndexPath], withRowAnimation: .None)
        } else {
            // Add a new event.
            let newIndexPath = NSIndexPath(forRow: events.count, inSection: 0)
            events.append(event)
            tableView.insertRowsAtIndexPaths([newIndexPath], withRowAnimation: .Bottom)
        }
        // Save the events.
        saveEvents()
    }
}

// MARK: NSCoding

func saveEvents() {
    let isSuccessfulSave = NSKeyedArchiver.archiveRootObject(events, toFile: Event.ArchiveURL.path!)
    if !isSuccessfulSave {
        print("Failed to save events...")
    }
}

func loadEvents() -> [Event]? {
    return NSKeyedUnarchiver.unarchiveObjectWithFile(Event.ArchiveURL.path!) as? [Event]
}
}

Console Output:

2015-11-27 22:10:15.492 TicketekApp[14326:6837851] - changing property masksToBounds in transform-only layer, will have no effect 2015-11-27 22:10:15.493 TicketekApp[14326:6837851] - changing property masksToBounds in transform-only layer, will have no effect 2015-11-27 22:10:15.494 TicketekApp[14326:6837851] - changing property masksToBounds in transform-only layer, will have no effect 2015-11-27 22:10:37.900 TicketekApp[14326:6837851] * Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Receiver () has no segue with identifier 'userEventTableViewControllerSegue'' * First throw call stack: ( 0 CoreFoundation 0x00251a94 exceptionPreprocess + 180 1 libobjc.A.dylib 0x0208fe02 objc_exception_throw + 50 2 UIKit 0x00e33960 -[UIViewController shouldPerformSegueWithIdentifier:sender:] + 0 3 TicketekApp 0x00023448 _TFC11TicketekApp24EventTableViewController9tableViewfS0_FTCSo11UITableView23didSelectRowAtIndexPathCSo11NSIndexPath_T_ + 424 4 TicketekApp 0x000234e9 _TToFC11TicketekApp24EventTableViewController9tableViewfS0_FTCSo11UITableView23didSelectRowAtIndexPathCSo11NSIndexPath_T_ + 89 5 UIKit 0x00dd5b79 -[UITableView _selectRowAtIndexPath:animated:scrollPosition:notifyDelegate:] + 1915 6 UIKit 0x00dd5dd0 -[UITableView _userSelectRowAtPendingSelectionIndexPath:] + 381 7 UIKit 0x00ddbff5 __38-[UITableView touchesEnded:withEvent:]_block_invoke + 57 8 UIKit 0x00c7c37b _runAfterCACommitDeferredBlocks + 337 9 UIKit 0x00c90839 _cleanUpAfterCAFlushAndRunDeferredBlocks + 103 10 UIKit 0x00c9e4db _afterCACommitHandler + 102 11 CoreFoundation 0x0016b77e __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION + 30 12 CoreFoundation 0x0016b6de __CFRunLoopDoObservers + 398 13 CoreFoundation 0x0016105c __CFRunLoopRun + 1340 14 CoreFoundation 0x00160866 CFRunLoopRunSpecific + 470 15 CoreFoundation 0x0016067b CFRunLoopRunInMode + 123 16 GraphicsServices 0x044c7664 GSEventRunModal + 192 17 GraphicsServices 0x044c74a1 GSEventRun + 104 18 UIKit 0x00c6ecc1 UIApplicationMain + 160 19 TicketekApp 0x000266cc main + 140 20 libdyld.dylib 0x02b00a21 start + 1 ) libc++abi.dylib: terminating with uncaught exception of type NSException (lldb)

Answers


you need to change below thing because you have mention wrong identifier, Also this class must have parent as UINavigationController

performSegueWithIdentifier("userEventTableViewControllerSegue", sender: self)

to

performSegueWithIdentifier("userEventViewControllerSegue", sender: self)

You are doing in your code

 performSegueWithIdentifier("userEventTableViewControllerSegue", sender: self)

But there is no segue name like that. You should check your storyboard to get the correct name.


i think the problem is in your segue like it says in the console "has no segue with identifier 'userEventTableViewControllerSegue'' "

go to storyboard and set that segue where it should be and.. it should work. :)


Need Your Help

iOS 7 Text Kit: When has NSLayoutManager filled its last NSTextContainer?

ios ios7 uipageviewcontroller textkit

I'm using Text Kit in combination with UIPageViewController to create a book. The original text is stored in a text file (.html) and placed into a NSTextStorage.

PHP random number in email

php html wordpress email

I have a Wordpress website where i am making a form so that when a user fills out that form he gets a confirmation email and receives a unique order number. I have this PHP function which creates t...