PDA

View Full Version : problem running accelerometer on device




medasmx
Oct 2, 2010, 05:25 AM
When I try to use an accelerometer program from the Big Nerd Ranch, iPhone book, on my iPhone device, I get the following error...

program received signal: "SIGABRT"
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[UIWindow setRootViewController:]: unrecognized selector sent to instance 0x118fe0'

The code is from Chapter 8 in the iPhone Big Nerd Ranch book. I have an old iPhone. My OS is 3.1.3 (bought phone in 2007). This program works fine on the simulator, but the accelerometer has no function on the simulator.

Below is the additional code added from a project that was essentially 2 views with a tab bar.


-(void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
NSLog(@"Monitoring accelerometer");
UIAccelerometer*a=[UIAccelerometer sharedAccelerometer];
[a setUpdateInterval:0.1];
[a setDelegate:self];
}

-(void)viewWillDisappear:(BOOL)animated
{
[super viewWillDisappear:animated];
[[UIAccelerometer sharedAccelerometer]setDelegate:nil];
}

-(void)accelerometer:(UIAccelerometer*)meter
didAccelerate:(UIAcceleration*)accel
{
HypnosisView*hv=(HypnosisView*)[self view];
[hv setXShift:10.0*[accel x]];
[hv setYShift:10.0*[accel y]];
[hv setNeedsDisplay];
}


Any help is appreciated. Thanks.

Adam



robbieduncan
Oct 2, 2010, 05:40 AM
Somewhere your memory management is messed up and you have ended up with a pointer to an object that you expected to be one type but it's another (most likely you failed to retain an object you should have or you released one you should not have).