Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Mockup & CodeGen, iPhone & iPad
($9.99)

Make your own iPhone apps
and run them live!
(free)

Manu
($0.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 02-25-2010, 09:14 AM   #1 (permalink)
Registered Member
 
Join Date: Sep 2009
Posts: 26
Default Problem with shakes: viewDidAppear isn't called when loading viewController

I'm trying to detect a shake on the iPhone device, so for what i've read I need to set my view controller as first responder on the viewDidAppear method. This method is supposed to be called automatically, but for some reason this method is never called. Only viewDidLoad is called.

this is my code (I put only the relevant parts):

BuildHouseViewController.h:
Code:
@interface BuildHouseViewController : UIViewController <UIAccelerometerDelegate>{

BuildHouseViewController.m:

Code:
- (void)viewDidLoad {
    [super viewDidLoad];
	[self.view becomeFirstResponder];
Code:
-(void)viewDidAppear:(BOOL)animated{
	[self becomeFirstResponder];
	[super viewDidAppear:animated];
}
-(void)viewWillAppear:(BOOL)animated{
	[self becomeFirstResponder];
	[super viewWillAppear:animated];
}

-(BOOL)canBecomeFirstResponder {
	return YES;
}
Code:
- (void)motionEnded:(UIEventSubtype)motion withEvent:(UIEvent *)event{
	
	NSLog(@"shake"); 
    if ( event.subtype == UIEventSubtypeMotionShake )
    {  }
	
    if ( [super respondsToSelector:@selector(motionEnded:withEvent:)] )
		[super motionEnded:motion withEvent:event];
	
}
I added breakpoints on the viewDidAppear and viewWillAppear methods and they are never called. Shakes are never detected, I suppose it is because as this methods are never called, the view controller can never become first responder. I don't understand why this is happening.

Any help will be appreciated.
fede is offline   Reply With Quote
Old 02-25-2010, 10:00 AM   #2 (permalink)
Registered Member
 
Join Date: Sep 2009
Posts: 26
Default

Is it possible that the reason for this is the way I load the view?

I load it from another view using:

Code:
BuildHouseViewController *nextScreen=[[BuildHouseViewController alloc] initWithNibName:@"BuildHouseViewController" bundle:nil];
		[self.view addSubview:nextScreen.view];
fede is offline   Reply With Quote
Old 10-30-2010, 11:05 PM   #3 (permalink)
Registered Member
 
Join Date: Nov 2009
Posts: 36
Default

I'm having same issue view 1 calls view 2 and in view 2 I have a shake gesture not responding. Did you come up with a solution?
bocephus_h@yahoo.com is offline   Reply With Quote
Old 10-30-2010, 11:37 PM   #4 (permalink)
Beast Mode
 
Join Date: Dec 2008
Age: 21
Posts: 1,890
Default

Quote:
Originally Posted by bocephus_h@yahoo.com View Post
I'm having same issue view 1 calls view 2 and in view 2 I have a shake gesture not responding. Did you come up with a solution?
I think the viewdidappear only gets called on a navigation stack not just adding a subview
__________________
I really do this.
Bertrand21 is offline   Reply With Quote
Reply

Bookmarks

Tags
first responder, shake, view controller, viewdidappear

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 259
18 members and 241 guests
14DEV, @sandris, ADY, ArtieFufkin10, bookesp, ckgni, Dani77, DarkAn, HemiMG, iDifferent, jakerocheleau, JasonR, prchn4christ, Rudy, ryantcb, Speed, theone8one
Most users ever online was 1,187, 10-11-2011 at 08:09 AM.
» Stats
Members: 158,885
Threads: 89,230
Posts: 380,767
Top Poster: BrianSlick (7,129)
Welcome to our newest member, bookesp
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 02:46 PM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0