views:

51

answers:

2

Hello every one, 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???

A: 

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: http://stackoverflow.com/questions/1340492/how-to-detect-and-program-around-shakes-for-the-iphone

Frank Shearar
+2  A: 

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

David Gelhar