Facebook Loginbutton issues
<p>I have a reader application which can post text to Facebook .I already done that,i have a login-button as same as the facebook-login button,the user can login there and i retrieve the username from the Facebook and display instead of loge-out button,that means when the user login and came back the login-button title changes to loge-out thats the default behavior of the Facebook connect button,but i changed a little and set the title as username of the correspondent user.My problem is  after login to the Facebook the the title of the button changes to username,but after redirected to some other page of the application and comes back it doesn't show the username the button title shows login.I tried a lot to solve this i even uses the NSUserDefault but no luck my entire code for this is</p>

<pre><code>- (IBAction)loginButtonTapped:(id)sender
{
    NSString *appId = @"HIDDEN1234";
    NSString *permissions = @"publish_stream";

    if (_loginDialog == nil) {
        self.loginDialog = [[[FBFunLoginDialog alloc] initWithAppId:appId requestedPermissions:permissions delegate:self] autorelease];
        self.loginDialogView = _loginDialog.view;

    }

    if (_loginState == LoginStateStartup || _loginState == LoginStateLoggedOut) {
        _loginState = LoginStateLoggingIn;
        [_loginDialog login];
         [[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"FB_logged"];
    } else if (_loginState == LoginStateLoggedIn) {
        _loginState = LoginStateLoggedOut;   
        _btnFacebookmain.enabled =NO;
        [_loginDialog logout];
        [[NSUserDefaults standardUserDefaults] setBool:NO forKey:@"FB_logged"];
    }

    [self refresh];


}
-(IBAction)_clickbtnFaacbukMain:(id)sender
{
    StatusViewController *detailViewController = [[StatusViewController alloc] initWithNibName:@"StatusViewController" bundle:nil];
    detailViewController.yourStringProperty = localStringValue;
    detailViewController.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
    [self presentModalViewController:detailViewController animated:YES];
    [UIView commitAnimations];
    [detailViewController release];
    UIView *popView = (UIView *)[self.view viewWithTag:106]; 
    //ViewWithTag Number should be same as used while allocating
    [popView removeFromSuperview];


}
- (void)refresh {
    if (_loginState == LoginStateStartup || _loginState == LoginStateLoggedOut) {
        _loginStatusLabel.text = @"Not connected to Facebook";
        [[NSUserDefaults standardUserDefaults] setBool:NO forKey:@"FB_logged"];
        [_loginButton setTitle:@"" forState:UIControlStateNormal];
        UIImage *buttonImage = [UIImage imageNamed:@"settings_connect1-facebook-icon"];
        [_loginButton setBackgroundImage:buttonImage forState:UIControlStateNormal];


        //[[NSUserDefaults standardUserDefaults]removeObjectForKey:@"FB_LOGIN_STATUS"];

        _loginButton.hidden = NO;
    } else if (_loginState == LoginStateLoggingIn) {
        _loginStatusLabel.text = @"Connecting to Facebook...";
        _loginButton.hidden = YES;
        UIImage *buttonImage = [UIImage imageNamed:@"settings_connect1-facebook-icon"];
        [_loginButton setBackgroundImage:buttonImage forState:UIControlStateNormal];


    } else if (_loginState == LoginStateLoggedIn) {
        _loginStatusLabel.text = @"Connected to Facebook";
        NSString *username = [_loginButton titleForState:UIControlStateNormal];
        [_loginButton setTitle:username forState:UIControlStateNormal];
        [_loginButton setBackgroundImage:nil forState:UIControlStateNormal];
       [[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"FB_logged"];
        _loginButton.hidden = NO;
    }   
}

- (void)getFacebookProfile {
    NSString *urlString = [NSString stringWithFormat:@"https://graph.facebook.com/me?access_token=%@", [_accessToken stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
    NSURL *url = [NSURL URLWithString:urlString];
    ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url];
    [request setDidFinishSelector:@selector(getFacebookProfileFinished:)];

    [request setDelegate:self];
    [request startAsynchronous];
}

#pragma mark FB Responses

- (void)getFacebookProfileFinished:(ASIHTTPRequest *)request
{
    // Use when fetching text data
    NSString *responseString = [request responseString];
    NSLog(@"Got Facebook Profile: %@", responseString);

    NSMutableDictionary *responseJSON = [responseString JSONValue];   

    NSString *username;
    NSString *firstName = [responseJSON objectForKey:@"first_name"];
    NSString *lastName = [responseJSON objectForKey:@"last_name"];
    if (firstName &amp;&amp; lastName) {
        username = [NSString stringWithFormat:@"%@ %@", firstName, lastName];
    } else {
        username = @"mysterious user";
    }
//[[NSUserDefaults standardUserDefaults] setObject:@"username" forKey:@"FB_LOGIN_STATUS"];
[_loginButton setTitle:username forState:UIControlStateNormal];

    [self refresh];    
}


#pragma mark FBFunLoginDialogDelegate

- (void)accessTokenFound:(NSString *)accessToken {
    NSLog(@"Access token found: %@", accessToken);
    self.accessToken = accessToken;

    _loginState = LoginStateLoggedIn;
    [self dismissModalViewControllerAnimated:YES];
    [self getFacebookProfile]; 
    [self refresh];
}

- (void)displayRequired {
    [self presentModalViewController:_loginDialog animated:YES];
}

- (void)closeTapped {
    [self dismissModalViewControllerAnimated:YES];
    _loginState = LoginStateLoggedOut;        
    [_loginDialog logout];
    [self refresh];
}
</code></pre>

<p>and in viewwillapper method</p>

<pre><code>BOOL loggedd = [[NSUserDefaults standardUserDefaults] boolForKey:@"FB_logged"];
if (loggedd == YES) {
    _btnFacebookmain.enabled = YES;
    NSString *username = [_loginButton titleForState:UIControlStateNormal];
    [_loginButton setTitle:username forState:UIControlStateNormal];
     //[self refresh];
}
else
{
    [_loginButton setTitle:@"" forState:UIControlStateNormal];
    _btnFacebookmain.enabled =NO;
   /* UIImage *buttonImage = [UIImage imageNamed:@"settings_connect1-facebook-icon"];
    [_loginButton setBackgroundImage:buttonImage forState:UIControlStateNormal];*/


}
</code></pre>

<p>please look into this code and help me to solve this.
Thanks in advance.</p>
