Note that there are some explanatory texts on larger screens.

plurals
  1. POWhy does popToRootViewContoller either freezes or takes a long time to perform?
    primarykey
    data
    text
    <p>I have setup some views with the navigation controller. I want to be able to go back to the original view when I shake the phone. First, here's the code snippet which I have in my AppDelegate:</p> <pre><code>- (void)startAccelerometerUpdates { [motionManager startDeviceMotionUpdatesToQueue:queue withHandler:^(CMDeviceMotion *motion, NSError *error) { // based from // http://stackoverflow.com/questions/5214197/simple-iphone-motion-detect/5220796#5220796 float accelerationThreshold = 1; // or whatever is appropriate - play around with different values CMAcceleration userAcceleration = motion.userAcceleration; if (fabs(userAcceleration.x) &gt; accelerationThreshold || fabs(userAcceleration.y) &gt; accelerationThreshold || fabs(userAcceleration.z) &gt; accelerationThreshold) { if(!self-&gt;isRoot) { NSLog(@"Stopping motion manager"); [motionManager stopDeviceMotionUpdates]; NSLog(@"popping to top view controller"); [navcon popToRootViewControllerAnimated:YES]; NSLog(@"Done popping"); } } }]; } - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { ..... motionManager = [[CMMotionManager alloc] init]; motionManager.deviceMotionUpdateInterval = .5; isRoot = malloc(sizeof(BOOL)); self-&gt;isRoot = NO; [self startAccelerometerUpdates]; [navcon pushViewController:main animated:NO]; .... } </code></pre> <p>I was expecting that the call to popToRoot would be immediate. However, it takes around 30 seconds. Interesting to note that the button on top that you could press to manually go back to the previous page doesn't work at this point. The phone seems to be doing a whole lot of work to freeze up the buttons. So, I'm definitely doing something wrong here. </p> <p>It thought that maybe I keep calling the popToRootViewController several times so I added a check "isRoot" as you see in the code (please don't distracted on why BOOL is a pointer, I have a reason for that).</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload