Accelerometer and shake in objective c
I've two questions:
1) in one of my viewControllers i write this method to find a customized shake:
- (void)accelerometer:(UIAccelerometer *)accelerometer didAccelerate:(UIAcceleration *)acceleration;
and i express accelerometer delegate in the .h
The problem is that iphone simulator doesn't detect it, is it normal?
2) With previous code in viewDidLoad I write:
UIAccelerometer *accell = [UIAccelerometer sharedAccelerometer];
[accell setDelegate:self];
[accell setUpdateInterval.....];
Now i want make a delegate class, so i will not write the code for each viewControl开发者_C百科ler. How can i do this? how will change code above?
In this way:
delegateClass *delegateAcceleration = [[delegateClass alloc]]init];
UIAccelerometer *accell = [UIAccelerometer sharedAccelerometer];
[accell setDelegate:delegateAcceleration];
[accell setUpdateInterval.....];
[delegateAcceleration release];
1) yes it is normal, simulator doesn't support accelerometer. There are third party tools that can help with it, like iSimulate. They run on the device and send acceleration data to you app running in simulator
2) wrong, you cannot release your delegate class because UIAccelerometer doesn't retain its delegate, if you release it right away it will break.
精彩评论