Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

iOS Build a Self-Destructing Message iPhone App Using Parse.com as a Backend and Adding Users Logging In and Logging Out

ivan hernandez
PLUS
ivan hernandez
Courses Plus Student 2,298 Points

How to change Title in UIBarButtonItem

I have a "Logout" button in the top left of the UItableview and I want to change the Title from "Logout" to "Salida" depending of the selection of "English" or "Spanish" what can I do?

2 Answers

Sam Chaudry
Sam Chaudry
25,519 Points

Heres how I would do it just to get you started

  1. You need to ask the user when they log in (when the app loads) if they want english or spanish you could pop it in the viewDidLoad method as a UI Alert i.e.

UIAlertView * alert =[[UIAlertView alloc ] initWithTitle:@"Welcome to my App" message:@"Choose your language" delegate:self cancelButtonTitle:@"English" otherButtonTitles: nil]; [alert addButtonWithTitle:@"Spanish"]; [alert show];

  1. Let them select which ever one they want

    • (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex

{ if (buttonIndex == 1) {
self.LogOutButton.text=@"English"; //sets it as English

    }

    else{
             self.LogOutButton.text=@"Salida"; //sets it as Spanish

}

Without seeing your code its hard to comment but that above is the line of thinking I would go down to get it working. Also note this is a global approach you could use this to modify the language across the class not just for one button

ivan hernandez
PLUS
ivan hernandez
Courses Plus Student 2,298 Points

Thank you Sam for your answer, what I was missing was that I had to make @porperty for uibarbutton that way you can change the title. thank you again.