开发者

UIAccelerometer called from subview not working

I have an "interesting" issue with the UIAccelerometer in an app for the iPad.

In my UIViewController I have a method that activates the Accelerometer. This is how it looks like:

-(void)startAcc{

UIAccelerometer *gForce = [UIAccelerometer sharedAccelerometer];
gForce.delegate = self;
gForce.updateInterval = kUpdateInterval;
}

In my viewWillAppear I call this method to activate the Accelerometer, and it works just fine. I recieve accelerations and use it to move a view on screen.

On user input I then load another view (UIView) that need to use the accelerometer. So I stop the accelerometer in my UIViewController with this code:

[UIAccelerometer sharedAccelerometer].delegate = nil;

I then load the UIView and activates the accelerometer there in the same way.开发者_如何学编程 All works just fine.

My issue begins when I want to close the UIView and start the accelerometer in the UIViewController again. I stop it in the UIView and call the startAcc method in my UIViewController from the UIView. The method executes, but I receive no accelerations :-(

Same method, but different results.

Can anyone guide me to what I am missing here?

Thanks


Solved it. By putting [self resignFirstResponder]; after I call the startAcc method from the subview it works.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜