Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to set title for UIButton?
    primarykey
    data
    text
    <p>How can we set the button title for a button,i know this answer its simple,we need to set the title of the button for title ,but my need is somewhat diffrent ,i had a username which dynamically changes according to login.i set this in a button click and display it in a label within that button .my code for this is</p> <pre><code>- (void)getFacebookProfileFinished:(ASIHTTPRequest *)request { // Use when fetching text data NSString *responseString = [request responseString]; NSLog(@"Got Facebook Profile: %@", responseString); NSString *likesString; 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"; } [_loginButton setTitle:username forState:UIControlStateNormal]; _lblfaceusername.text = username; [self refresh]; } </code></pre> <p>i need to display the user name in another button click and have to assing the title of that button to user name the code for this is</p> <pre><code>- (void)refresh { if (_loginState == LoginStateStartup || _loginState == LoginStateLoggedOut) { _loginStatusLabel.text = @"Not connected to Facebook"; [_loginButton setTitle:@"Login" forState:UIControlStateNormal]; _loginButton.hidden = NO; } else if (_loginState == LoginStateLoggingIn) { _loginStatusLabel.text = @"Connecting to Facebook..."; _loginButton.hidden = YES; } else if (_loginState == LoginStateLoggedIn) { _loginStatusLabel.text = @"Connected to Facebook"; [_loginButton setTitle:@"" forState:UIControlStateNormal]; _loginButton.hidden = NO; } } </code></pre> <p>i need to set the username in the <code>[_loginButton setTitle:@"" forState:UIControlStateNormal];</code>i want <code>[_loginButton setTitle:username forState:UIControlStateNormal]</code>;</p>
    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.
 

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