iPhone: UILabel applying CGAffineTransformMakeRotation causing mysterious crash
In
-(id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil parentController:(GameViewController *)myGameController{
Have a series of transforming labels like so:
deg90 = 1.570796326794897;
//....transforms
background.center = CGPointMake(160,230);
background.transform = CGAffineTransformMakeRotation(deg90);
BetLabel.text = @"test";
BetLabel.transform = CGAffineTransformMakeRotation(deg90);
That last line is crashing me with:
2010-04-13 21:04:47.858 Game[1204:207] *** Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[NSCFArray objectAtIndex:]: index (1) beyond bounds (1)'
2010-04-13 21:04:47.893 Game[1204:207] Stack: (
864992541,
859229716, (lots of numbers)
But if I comment it out, I get the text changing fine.
Update: Uh oh, just did a test.. turns out the other transforms were on UIImageViews. Apparently rotating a label in this xib is causing the crash.
But in another file the transforms are working fine:
newprofileentry.transform = CGAffineTransformMakeRotation(1.570796326794897);
pla开发者_如何学运维yerb0.transform = CGAffineTransformMakeRotation(1.570796326794897);
playerb1.transform = CGAffineTransformMakeRotation(1.570796326794897);
Tried substituting deg90
with the full float value, still the same crash.
Tried cleaning cache, restarting IB and Xcode, cleaning all targets. Program has been running fine until I just added these labels. Tried deleting the label, readding and reconnecting the Outlet, too.
Thanks for reading, hope someone has an idea about this.
Cheers!
I suggest moving the transforms out of initWithNib:
It's possible that the you're trying to modify something that doesn't yet exist because the objects in the nib are still initializing.
You should also examine the nib file (in Interface Builder or with ibtool) to see if there is something scrambled with that particular label. To test that, you could swap out its order in the initialization with another label to see if the problem is with that particular label or whether it is with any label or object in the last position.
Posting more code in context would probably help.
精彩评论