2011-04-29 57 views
0

我有两个问题:加速度计和动摇的目标C

1)在我viewControllers之一,我写这篇文章的方法来找到一个定制的震动:

- (void)accelerometer:(UIAccelerometer *)accelerometer didAccelerate:(UIAcceleration  *)acceleration; 

和我表达加速度计代表在.h

问题是,iPhone模拟器没有检测到它,这是正常的吗?

2)随着viewDidLoad中前面的代码我写:

UIAccelerometer *accell = [UIAccelerometer sharedAccelerometer]; 
[accell setDelegate:self]; 
[accell setUpdateInterval.....]; 

现在我希望做一个委托类,所以我不会写每一个的viewController的代码。 我该怎么做?如何更改上面的代码?

这样:

delegateClass *delegateAcceleration = [[delegateClass alloc]]init]; 
UIAccelerometer *accell = [UIAccelerometer sharedAccelerometer]; 
[accell setDelegate:delegateAcceleration]; 
[accell setUpdateInterval.....]; 
[delegateAcceleration release]; 

回答

0

1)是的,它是正常的,模拟器不支持加速度计。有第三方工具可以帮助它,比如iSimulate。 2)错误的,你不能释放你的委托类,因为UIAccelerometer不保留它的委托,如果你马上释放它,它将会中断。