I want to change the row selection by shaking my iphone. i.e. as soon as I shake my iphone, the next row should be selected of tableview. And according to that another operation should be perform. can any one tell???
Asked
Active
Viewed 246 times
2 Answers
2
Apple's iPhone Human Interface Guidelines warn against defining your own meaning for the shake gesture:
Avoid overloading the shake gesture. Even though you can programmatically set when your application interprets a shake event as shake to undo, you run the risk of confusing users if they also use shake to perform a different action.
For how to actually use the Shake iPhone API, here's a similar question

Community
- 1
- 1

David Gelhar
- 27,873
- 3
- 67
- 84
0
Use an UIAccelerometer. Implement the UIAccelerometerDelegate protocol, and do something like
- (void)accelerometer:(UIAccelerometer *)accelerometer didAccelerate:(UIAcceleration *)acceleration {
UIAccelerationValue threshold = 2.0;
if ((fabsf(acceleration.x) > threshold) || (fabsf(acceleration.y) > threshold) || (fabsfacceleration.z) > threshold) {
[self advanceRow];
}
}
with an appropriately defined -[YourClass advanceRow]. Try out different values for threshold for a sensitive wiggle or a violent shake.
But also see this answer: how to detect and program around shakes for the iphone

Community
- 1
- 1

Frank Shearar
- 17,012
- 8
- 67
- 94