-1

Dear fellow iOS Developers,

ever since using iOS 10 Beta with Xcode 8 Beta and migrating to Swift 3 I have noticed strange behaviour in my app when using custom UITableViewCells. When I try to dequeue a custom cell in cellForRowAtIndexPath I get a crash with an NSException - except for when I register the cells manually in code. This does not happen with all custom cells though, and I don't know why some cells get registered, and some don't. When I manually register the cells in code, the custom content does not get shown, instead they appear just plain white. This means that Storyboard for some reason cannot register the cells correctly.

  • I'm using Prototype Cells.
  • The cell identifiers are the same in Storyboard and in cellForRowAtIndexPath.
  • I'm using iOS 10 Beta 2 and Xcode 8 Beta 2 (though it already happened with the first betas.)
  • I'm using Swift 3.

Anyone here having the same problem? It's totally driving me nuts, and I am running out of ideas on how to fix this issue.

-> This works, but results in blank cells:

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
    tableView.register(ProgressCell.self, forCellReuseIdentifier: Storyboard.progressCell)
    let cell = tableView.dequeueReusableCell(withIdentifier: Storyboard.progressCell) as! ProgressCell

  **Configuring the cell here**

    return cell
}

-> This crashes the app:

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
    let cell = tableView.dequeueReusableCell(withIdentifier: Storyboard.progressCell) as! ProgressCell

    **Configuring the cell here**

    return cell
}

Storyboard.progressCell is using a struct where I store all my storyboard identifiers.

Everything worked just fine before updating to the new version of Xcode and Swift 3.

THIS IS THE CRASH LOG:

2016-07-06 20:47:30.049 MYAPP[59012:8826287] -[UIImageView imageOrientation]: unrecognized selector sent to instance 0x7ff5d361f590
2016-07-06 20:47:30.059 MYAPP[59012:8826287] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UIImageView imageOrientation]: unrecognized selector sent to instance 0x7ff5d361f590'
*** First throw call stack:
(
    0   CoreFoundation                      0x000000010614e9bb __exceptionPreprocess + 171
    1   libobjc.A.dylib                     0x00000001057a731e objc_exception_throw + 48
    2   CoreFoundation                      0x00000001061badb4 -[NSObject(NSObject) doesNotRecognizeSelector:] + 132
    3   CoreFoundation                      0x00000001060d4ee5 ___forwarding___ + 1013
    4   CoreFoundation                      0x00000001060d4a68 _CF_forwarding_prep_0 + 120
    5   UIKit                               0x00000001072236a7 -[UIImageView _updateImageViewForOldImage:newImage:] + 358
    6   UIKit                               0x000000010721edab -[UIImageView setImage:] + 391
    7   UIKit                               0x00000001073c57f7 -[UITableViewCell setImage:] + 79
    8   Foundation                          0x00000001052c8b7f -[NSObject(NSKeyValueCoding) setValue:forKey:] + 291
    9   UIKit                               0x00000001070d4195 -[UIView(CALayerDelegate) setValue:forKey:] + 173
    10  UIKit                               0x000000010740ce72 -[UIRuntimeOutletConnection connect] + 109
    11  CoreFoundation                      0x00000001060f4bb0 -[NSArray makeObjectsPerformSelector:] + 256
    12  UIKit                               0x000000010740b7f6 -[UINib instantiateWithOwner:options:] + 1867
    13  UIKit                               0x0000000107168a0d -[UITableView _dequeueReusableViewOfType:withIdentifier:] + 368
    14  UIKit                               0x0000000107168f08 -[UITableView dequeueReusableCellWithIdentifier:forIndexPath:] + 71
    15  MYAPP                            0x0000000104f0808a _TTSf4g_g_d___TFC8MYAPP22ProgressViewController9tableViewfTCSo11UITableView12cellForRowAtV10Foundation9IndexPath_CSo15UITableViewCell + 138
    16  MYAPP                            0x0000000104f0717f _TToFC8MYAPPe22ProgressViewController9tableViewfTCSo11UITableView12cellForRowAtV10Foundation9IndexPath_CSo15UITableViewCell + 63
    17  UIKit                               0x000000010717c16a -[UITableView _createPreparedCellForGlobalRow:withIndexPath:willDisplay:] + 746
    18  UIKit                               0x000000010717c2c6 -[UITableView _createPreparedCellForGlobalRow:willDisplay:] + 74
    19  UIKit                               0x000000010715053e -[UITableView _updateVisibleCellsNow:isRecursive:] + 3295
    20  UIKit                               0x0000000107185221 -[UITableView _performWithCachedTraitCollection:] + 110
    21  UIKit                               0x000000010716c1db -[UITableView layoutSubviews] + 222
    22  UIKit                               0x00000001070d47bf -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 956
    23  QuartzCore                          0x000000010edca278 -[CALayer layoutSublayers] + 146
    24  QuartzCore                          0x000000010edbdd3c _ZN2CA5Layer16layout_if_neededEPNS_11TransactionE + 366
    25  UIKit                               0x00000001070c290b -[UIView(Hierarchy) layoutBelowIfNeeded] + 275
    26  UIKit                               0x00000001071f05ea -[UINavigationController _layoutViewController:] + 1625
    27  UIKit                               0x00000001071ef418 -[UINavigationController _layoutTopViewController] + 341
    28  UIKit                               0x00000001071ec811 -[UINavigationController navigationTransitionView:didEndTransition:fromView:toView:] + 874
    29  UIKit                               0x00000001074c1278 -[UINavigationTransitionView _notifyDelegateTransitionDidStopWithContext:] + 418
    30  UIKit                               0x00000001074c15da -[UINavigationTransitionView _cleanupTransition] + 766
    31  UIKit                               0x000000010709daed -[UIViewAnimationState sendDelegateAnimationDidStop:finished:] + 222
    32  UIKit                               0x00000001070995bd +[UIViewAnimationState popAnimationState] + 307
    33  UIKit                               0x00000001074c0fee -[UINavigationTransitionView transition:fromView:toView:] + 2808
    34  UIKit                               0x00000001071f1697 -[UINavigationController _startTransition:fromViewController:toViewController:] + 3314
    35  UIKit                               0x00000001071f1c37 -[UINavigationController _startDeferredTransitionIfNeeded:] + 876
    36  UIKit                               0x00000001071f2d5d -[UINavigationController __viewWillLayoutSubviews] + 58
    37  UIKit                               0x00000001073da66f -[UILayoutContainerView layoutSubviews] + 223
    38  UIKit                               0x00000001070d47bf -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 956
    39  QuartzCore                          0x000000010edca278 -[CALayer layoutSublayers] + 146
    40  QuartzCore                          0x000000010edbdd3c _ZN2CA5Layer16layout_if_neededEPNS_11TransactionE + 366
    41  QuartzCore                          0x000000010edbdbba _ZN2CA5Layer28layout_and_display_if_neededEPNS_11TransactionE + 24
    42  QuartzCore                          0x000000010ed4be98 _ZN2CA7Context18commit_transactionEPNS_11TransactionE + 280
    43  QuartzCore                          0x000000010ed78f7f _ZN2CA11Transaction6commitEv + 475
    44  QuartzCore                          0x000000010ed798eb _ZN2CA11Transaction17observer_callbackEP19__CFRunLoopObservermPv + 113
    45  CoreFoundation                      0x00000001060f4437 __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 23
    46  CoreFoundation                      0x00000001060f43a7 __CFRunLoopDoObservers + 391
    47  CoreFoundation                      0x00000001060d8dfe __CFRunLoopRun + 1198
    48  CoreFoundation                      0x00000001060d86ed CFRunLoopRunSpecific + 285
    49  GraphicsServices                    0x000000010abfda75 GSEventRunModal + 161
    50  UIKit                               0x00000001070123b9 UIApplicationMain + 159
    51  MYAPP                            0x0000000104eda173 main + 99
    52  libdyld.dylib                       0x0000000109ad768d start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb) 
Valentin
  • 29
  • 5
  • Could you update your post with code of cellForRowAtIndexPath function – Ludovic Jul 06 '16 at 18:18
  • I don't understand why you are storing many cell identifiers ?? You just need one – Ludovic Jul 06 '16 at 18:38
  • I store all storyboard identifiers in there, such as segue identifiers and cell identifiers. – Valentin Jul 06 '16 at 18:39
  • And you not using indexPath to dequeue ? Each cell got a uniq identifier ? – Ludovic Jul 06 '16 at 18:41
  • You're right, I forgot to add the indexPath. This does not fix the the issue unfortunately. Yes, every table view cell has a unique identifier. – Valentin Jul 06 '16 at 18:45
  • It's not just unwrapping a `nil`, is it? What does the exception say? – NRitH Jul 06 '16 at 18:46
  • updated my code showing the crash log. I guess it has something do with the UIImage in my cell not orienting correctly? – Valentin Jul 06 '16 at 18:50
  • The exception is curious, reporting that it tried to call `imageOrientation` (a `UIImage` method) on an image view. Are you positive the error is in the code you shared with us? The error is the sort of thing that you'd get if you passed an image view to something expecting an image. Why have you concluded the error rests in the code you shared with us thus far? I'd personally suspect the "configure cell" code (notably anything to do with image views) that you haven't shared with us. – Rob Jul 06 '16 at 19:06
  • Maybe an outlet is pointing to a `UIImage` instead of a `UIImageView`, or vice versa. – NRitH Jul 06 '16 at 19:08
  • In my configureCell: method I set the image of the UIImageView in my UITableViewCell subclass to be an image in my project assets. I figured the code I posted is at fault because I set breakpoints, and the app always crashes when attempting to dequeue a cell. – Valentin Jul 06 '16 at 19:49
  • Thank you so much, NRitH! For this particular cell, this was actually the case. I configured an outlet, deleted it, and forgot about it, yet it was still connected in Interface Builder. – Valentin Jul 06 '16 at 20:02
  • 1
    The problem is, Interface Builder connects my outlets to the wrong class - It changes the class name to a name I never used in my project, thats why the crash happens with my other cell subclasses. – Valentin Jul 06 '16 at 20:14
  • 1
    Valentin, you should go ahead and [post an answer to your own question](http://stackoverflow.com/help/self-answer). – Rob Jul 07 '16 at 00:48

1 Answers1

0

This issue might be due to the connection between controls and variables on storyboard. Please check the outlet variables if there are unused or unconnected outlet variables

  • Especially for controls on your custom table view cell and its outlet variables on tableview cell class. – tell me Jan 04 '17 at 12:44