Śledzę samouczek iOS dotyczący wylogowania na Facebooku.
Dodałem kod samouczka do mojego pliku delegata .m. Uruchomiłem go, a kiedy kliknąłem przycisk Wyloguj, zawiesza się. Nie wiem co oznacza błąd. Okno dziennika pokazuje:
[S3DEngine_AppDelegate logoutButtonClicked]: nierozpoznany selektor wysłany do instancji 0xb011dd0
Używam iPhone Simulator 5.0, XCode 4.2. Różnica w samouczku polega na tym, że NIE używam applicationDidFinishLauchingWithOptions:
. Próbowałem też tej funkcji, ale to ten sam błąd.
Dzięki za wszelką pomoc
- (void)applicationDidFinishLaunching:(UIApplication *)application
{
// Facebook
// Add the logout button
UIButton *logoutButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
logoutButton.frame = CGRectMake(40, 40, 200, 40);
[logoutButton setTitle:@"Log Out" forState:UIControlStateNormal];
[logoutButton addTarget:self action:@selector(logoutButtonClicked)
forControlEvents:UIControlEventTouchUpInside];
[self.viewController.view addSubview:logoutButton];
// Disable idle timer
//
[application setIdleTimerDisabled:YES] ;
// Configure and start the accelerometer
//
[[UIAccelerometer sharedAccelerometer] setUpdateInterval:kAccelerometerFrequency] ;
[[UIAccelerometer sharedAccelerometer] setDelegate:self] ;
// Create the view controller
//
[window addSubview:viewController.glView];
[window makeKeyAndVisible];
// Configure and start animation
//
viewController.glView.iAnimationInterval = kAnimationFrequency ;
[viewController.glView startAnimation];
// Configure ans start slpash view
//
CGRect frame = [[UIScreen mainScreen] bounds];
splashView = [[UIImageView alloc] initWithFrame:frame];
splashView.image = [UIImage imageNamed: @"Default.png"];
[window addSubview:splashView];
[window bringSubviewToFront:splashView];
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.5];
[UIView setAnimationTransition:UIViewAnimationTransitionNone forView:window cache:YES];
[UIView setAnimationDelegate:self];
[UIView setAnimationDidStopSelector:@selector(startupAnimationDone:finished:context:)];
splashView.alpha = 0.0;
[UIView commitAnimations];
// Play default movie if any
//
[viewController.glView playDefaultMovieIfAny];
facebook = [[Facebook alloc] initWithAppId:@"105441111111111" andDelegate:self];
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
if ([defaults objectForKey:@"FBAccessTokenKey"]
&& [defaults objectForKey:@"FBExpirationDateKey"])
{
facebook.accessToken = [defaults objectForKey:@"FBAccessTokenKey"];
facebook.expirationDate = [defaults objectForKey:@"FBExpirationDateKey"];
}
if (![facebook isSessionValid])
{
[facebook authorize:nil];
}
}
- (void) logoutButtonClicked:(id)sender
{
[facebook logout];
}
- (void) fbDidLogout
{
// Remove saved authorization information if it exists
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
if ([defaults objectForKey:@"FBAccessTokenKey"]) {
[defaults removeObjectForKey:@"FBAccessTokenKey"];
[defaults removeObjectForKey:@"FBExpirationDateKey"];
[defaults synchronize];
}
}
2 odpowiedzi
Rób jak to...
[logoutButton addTarget:self action:@selector(logoutButtonClicked:)
forControlEvents:UIControlEventTouchUpInside];
LUB
- (void) logoutButtonClicked
{
[facebook logout];
}
Jeśli chcesz zachować parametr (id)sender w funkcji logoutButtonClicked, funkcja selektora „logoutButtonClicked” musi mieć po nim średnik, jak widać poniżej:
[logoutButton addTarget:self action:@selector(logoutButtonClicked:)
Dodatkową lekturę na ten temat można znaleźć w dokumentacji Apple na Selectors: http://developer.apple.com/ biblioteka/ios/#documentation/cocoa/conceptual/objectivec/Chapters/ocSelectors.html
Podobne pytania
Nowe pytania
iphone
NIE używaj tego znacznika, chyba że adresujesz konkretnie iPhone'a i / lub iPoda touch firmy Apple. W przypadku pytań niezależnych od sprzętu użyj tagu [ios]. Więcej tagów do rozważenia to [xcode] (ale tylko jeśli pytanie dotyczy samego IDE), [swift], [objective-c] lub [cocoa-touch] (ale nie [cocoa]). Proszę powstrzymać się od pytań dotyczących iTunes App Store lub iTunes Connect. Jeśli używasz języka C #, oznacz tagiem [mono].