views:

263

answers:

1

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);
    playerb0.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!

A: 

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.

TechZen
Thanks everyone for the answers.Bizzarely, putting newt = [[gametoken alloc] init]; [gametokens2 addObject:newt]; [newt release];instead of inside of a for loop did the trick. Not sure why.. but it works now. Was crashing on accessing index 1 of that object. Don't know why the label would related to that. Strange memory error?
quantumpotato