我有两个问题:
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 :(得分:0)
1)是的,这是正常的,模拟器不支持加速度计。有些第三方工具可以帮助它,比如iSimulate。它们在设备上运行并将加速数据发送到在模拟器中运行的应用程序
2)错误,您无法释放您的委托类,因为UIAccelerometer不会保留其委托,如果您立即释放它将会中断。