What causes this error? "CALayer position contains NaN: [240 nan]"
(Decided to take this out of comments and put it as an answer, since I think it's a darned good answer :)
Ha! I had an NaN calculation (div0), too. Key debugging aid: the message in question is output by NSLog(), so set a breakpoint on NSLog() and watch what the OS is doing at that time. For me, it was myUISlider.value = NaN.
To set breakpoint:
XCode 3.x
- CMD-SHIFT-Y (debug window.)
- Breakpoints button.
- "Double-click for symbol"
- Type in "NSLog" (no quotes.)
XCode 4.x
- CMD-6 (breakpoints navigator.)
- "+" to add breakpoint (lower left.)
- Select ADD SYMBOLIC BREAKPOINT.
- Symbol: NSLog
- Confirm: Done.
XCode 5.x - 7.1 (at least) (Same as 4.x, except breakpoints navigator is CMD-7, now.)
Run app, watch it break on NSLog, check the stack traces.
I've found the problem.
When you reset the frame of a tableview
, it calls the delegate method tableView:heightForRowAtIndexPath:
for each row in the table so it can recalculate its content size if it needs to. At that point, we do some special handling to return the height, and due to some bad assumptions in our code, we mistakenly returned NaN
due to a divide by zero error (the variable we divide by was assumed to never be zero). Making sure that we do not divide by zero here fixed it.
I've spent a day trying to find the code that causes same problem and solved it within a minutes after enabling "break on exception" in Xcode. Check this tutorial to see how to enable it.