Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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.