简体   繁体   中英

exception for app in release mode, not in debug mode

I'm having an exception in my didSelectRowAtIndexPath method and i'm not quite sure why. I'm showing the user a list of possibilities they can select from, the UITableView is populated based on values stored in Core Data. The currently selected item has a Checkmark indicator. My method is below:

override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
    tableView.deselectRowAtIndexPath(indexPath, animated: true)

    let value = self.fetchedResultsController.objectAtIndexPath(indexPath) as CoreDataObject
    currentSelected = value.id as Int

    self.tableView.reloadData()
}

In development mode it's fine, but in production and testflight it crashes in this method. The crash log is below:

Crashed Thread 0 :
0   CoreFoundation  0x25f41a7d  _CFRetain + 165
1   UIKit   0x29619d67  -[UITableView _selectRowAtIndexPath:animated:scrollPosition:notifyDelegate:] + 919
2   UIKit   0x296cb9df  -[UITableView _userSelectRowAtPendingSelectionIndexPath:] + 195
3   UIKit   0x2957da25  _applyBlockToCFArrayCopiedToStack + 309
4   UIKit   0x294f982b  _afterCACommitHandler + 459
5   CoreFoundation  0x26007d95  __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 21
6   CoreFoundation  0x26005453  __CFRunLoopDoObservers + 279
7   CoreFoundation  0x2600585b  __CFRunLoopRun + 915
8   CoreFoundation  0x25f533c1  CFRunLoopRunSpecific + 477
9   CoreFoundation  0x25f531d3  CFRunLoopRunInMode + 107
10  GraphicsServices    0x2d3510a9  GSEventRunModal + 137
11  UIKit   0x29562fa1  UIApplicationMain + 1441

Is there anything i'm missing here? Why is this method crashing? I'm simply storing the currently selected ID and then reloading data so that it can show a checkmark after the reload. Is there something i'm missing here? It should be as simple as just getting the new id and then reloading the data.

The CoreDataObject that i'm using is from Objective-C and the id field is an NSNumber .

I tried other solutions below:

Crash when calling selectRowAtIndexPath:animated:scrollPosition:

iphone app crash at -[UITableView _selectRowAtIndexPath:animated:scrollPosition:notifyDelegate:]

iOS - didSelectRowAtIndexPath causes crash in app

In case anybody else has this issue. currentSelected was a global variable declared as Int and the value object has an id field thats `NSNumber. I changed it to the below and it works:

self.currentSelected = value.id.integerValue

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