Note that there are some explanatory texts on larger screens.

plurals
  1. POFacebook tutorial add logout button but blank screen
    primarykey
    data
    text
    <p>I'm very new to objective C. I followed the tutorial for integrating Facebook to iOS app and did nothing else. After I added the code for logout button stuff, I ran it and it gave me an error at line : <code>[self.viewController.view addSubview:logoutButton];</code> The error is "unrecognized selector sent to instance 0x6b6c550". I know this might be a stupid error but if anyone can point out where I'm wrong I would be very appreciated!</p> <pre><code>static NSString* kAppId = @"340105106048288"; // Method that gets called when the sign out button is clicked - (void)logoutButtonClicked { [facebook logout]; } - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions (NSDictionary *)launchOptions { 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]; facebook = [[Facebook alloc] initWithAppId:kAppId andDelegate:self]; NSUserDefaults* defaults = [NSUserDefaults standardUserDefaults]; if ([defaults objectForKey:@"FBAccessTokenKey"] &amp;&amp; [defaults objectForKey:@"FBExpirationDateKey"]) { facebook.accessToken = [defaults objectForKey:@"FBAccessTokenKey"]; facebook.expirationDate = [defaults objectForKey:@"FBExpirationDateKey"]; } // This part, the authorize method will bring you to the authorization page if (![facebook isSessionValid]) [facebook authorize:nil]; return YES; } // Pre iOS 4.2 support - (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url { return [facebook handleOpenURL:url]; } // For iOS 4.2+ support - (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation { return [facebook handleOpenURL:url]; } // Save the user credential, specifically the access token and the expiration date to the user defaults - (void)fbDidLogin { NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; [defaults setObject:[facebook accessToken] forKey:@"FBAccessTokenKey"]; [defaults setObject:[facebook expirationDate] forKey:@"FBExpirationDateKey"]; [defaults synchronize]; } - (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]; } } </code></pre>
    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.
    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