I understand this problem from one of my own projects. Usually when setFrame: crashes because you are trying to set NaN (not a number). I don’t know if you have practiced NaN before, but if you haven’t left a comment, I will provide information on how to deal with it.
EDIT: It's time to think that I can give you an example.
So, here is a sample code to explain why the error is hard to reproduce and how to fix it. I don’t know what your code looks like, but your problem sounds so much that I believe that you made the same mistake as me.
Consider the following code:
- (void)layoutSubviews { CGRect imageFrame; switch (self.state) { case 0: imageFrame = CGRectMake(0, 0, 100, 100); case 1: imageFrame = CGRectMake(10, 10, 50, 50); } self.imageView.frame = imageFrame; }
We believe that self.state is 2, then the imageFrame will never be initialized and will contain everything that was in this memory location, possibly NaN. The reason this is difficult to reproduce is because a failure will only occur when NaN is in this cell.
In my example, the error is very easy to determine, and it is probably not easy to notice in your code. If you can’t find it on your own, feel free to post your code and I’ll take a look at it. If you have any questions, feel free to leave comments.
source share