OK so I just debugged this problem myself and since this is an unanswered post I thought I'd explain how I fixed it.
In my case the error was caused by trying to get the tag of a UIImageView without an assigned tag.
First I tried the obvious solutions:
- quit xcode and simulator, reopen, try to build again
- restart computer, reopen, try to build again
- perform clean (cmd + shift + K).
None of these worked so I looked back at the seemingly innocent changes I made in the code.
This caused a crash:
if (!([[buttonsArray objectAtIndex:i] tag] > 299 )) {
//NSLog(@"removed [buttonsArray removeObjectAtIndex:i]:%@",[buttonsArray removeObjectAtIndex:i]);
[buttonsArray removeObjectAtIndex:i];
}
This Didnt:
if ([[buttonsArray objectAtIndex:i] class] != [UIButton class] ) {
//NSLog(@"removed [buttonsArray removeObjectAtIndex:i]:%@",[buttonsArray removeObjectAtIndex:i]);
[buttonsArray removeObjectAtIndex:i];
}
My array contained 3 UIButtons, each with tag greater than 299 and one UIImageView. An NSLog of the Array shows:
2012-05-10 01:46:14.555 My Application[542:fe03] buttonsArray:(
"<UIImageView: 0x6b7f940; frame = (0 0; 252 272); opaque = NO; userInteractionEnabled = NO; layer = <CALayer: 0x6b71dc0>>",
"<UIButton: 0x6b7ae70; frame = (8 8; 53 53); opaque = NO; tag = 300; layer = <CALayer: 0x6b6fb70>>",
"<UIButton: 0x6b8be00; frame = (69 8; 53 53); opaque = NO; tag = 301; layer = <CALayer: 0x6b8bd70>>",
"<UIButton: 0x6b8c1b0; frame = (130 8; 53 53); opaque = NO; tag = 302; layer = <CALayer: 0x6b8c140>>"
)
So the problem was that the UIImageView didn't have a tag assigned to it. When I tried to compare its sign to 299, the compiler threw this error. I thought that this would be ok (I read somewhere that unassigned tags default to 0) but I guess not!