Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6840665
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T23:52:17+00:00 2026-05-26T23:52:17+00:00

#pragma mark SA_OAuthTwitterControllerDelegate – (void) OAuthTwitterController: (SA_OAuthTwitterController *) controller authenticatedWithUsername: (NSString *) username {

  • 0
#pragma mark SA_OAuthTwitterControllerDelegate
- (void) OAuthTwitterController: (SA_OAuthTwitterController *) controller authenticatedWithUsername: (NSString *) username {
    NSLog(@"Authenicated for %@", username);
    [_btnTwitter setTitle:username forState:UIControlStateNormal];
}

I have this code for displaying username for twitter ,and it works well,but when i navigate to another page and came back the title username of the button disappears,i know we have to set a NSUserDefault value in viewwillapper for checking the username exists or not.But i didn’t know how to handle the nSUserDefault,if anyone have an idea to solve this issue please help me.
Thanks in advance.
EDIT:

- (void)viewWillAppear:(BOOL)animated{
    //Sets up the NSUserDefaults
    //Sets up the NSUserDefaults
    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];

    //Checks if there is a saved User Name    
    if([defaults objectForKey:@"kTwitterUserName"])
        NSString *username = [defaults objectForKey:@"kTwitterUserName"];
      [_btnTwitter setTitle:username forState:UIControlStateNormal];
    else
    {

    }

this is how my viewwillappear lokks
and

- (void) OAuthTwitterController: (SA_OAuthTwitterController *) controller authenticatedWithUsername: (NSString *) username {
    NSLog(@"Authenicated for %@", username);
    [_btnTwitter setTitle:username forState:UIControlStateNormal];
    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
    [defaults setObject:username forKey:@"kTwitterUserName"];
    [defaults synchronize];
    }

this is how my twitermethod looks like

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T23:52:18+00:00Added an answer on May 26, 2026 at 11:52 pm

    NSUserDefaults are very simple to work with. They are kind of like a dictionary, you set an object and a key. So to do what your trying to do, you can use something like the following:

    //This just sets up the defaults - similar to allocating a dictionary
    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
    

    Then to set an object in your defaults, you set an object/key pair like this:

    [defaults setObject:username forKey:@"kTwitterUserName"];
    

    It is important to call this method at some point: [defaults synchronize];. This explicitly saves the defaults. So you might as well do it immediately after you set the username key.

    Then to read the saved username:

     NSString *username = [defaults objectForKey:@"kTwitterUserName"];
    

    Your oAuth Method should look like this:

    - (void) OAuthTwitterController: (SA_OAuthTwitterController *) controller authenticatedWithUsername: (NSString *) username {
         //Any thing else you want to do - NSLogs, etc.
    
         NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
         [defaults setObject:username forKey:@"kTwitterUserName"];
         [defaults synchronize];
    }
    

    So your viewWillAppear will look something like this:

    - (void)viewWillAppear:(BOOL)animated
    {
        [super viewWillAppear:animated];
    
        //Sets up the NSUserDefaults
        NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
    
        //Checks if there is a saved User Name    
         if([defaults objectForKey:@"kTwitterUserName"]) {
             NSString *username = [defaults objectForKey:@"kTwitterUserName"];
        } else
            //Do something else because there is no saved username
            NSLog(@"no username saved");
    }
    

    Let me know in a comment if you need any clarification.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following ADBannerViewDelegate implementations: #pragma mark ADBannerViewDelegate Methods - (void)bannerViewDidLoadAd:(ADBannerView *)banner {
#pragma mark Internal API I've seen this in a book called xcode_quick_tour_iphoneOS. Does someone
I am getting leak at [pool release]; My code here is: #pragma mark UISearchBarDelegate
I'm capturing images using this code #pragma mark - image capture // Create and
I'm arranging my methods into groups using #pragma mark in implementation. But sometimes, the
I'm pretty sure this isn't a duplicate. Do you use #pragma mark? I've seen
I get a EXC_BAD_ACCESS when this delegate function is called : OAuthTwitterController: (SA_OAuthTwitterController *)
I'm using #pragma mark - Description all over my source code to use with
I was following the code here #pragma mark UITextFieldDelegate - (BOOL)textFieldShouldReturn:(UITextField *)textField { [textField
I'm trying to find where I can see the result of #pragma mark s

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.