sbjluke
sbjluke

Reputation: 309

Change the label of a UITabBarItem from different View

This is mainly a delegation question because I'm still learning and don't get it. I don't know how to go about creating the delegate I need.

I have a tabbed view controllerwith 2 views, let's call them view 1 and view 2. Then I have a settings view which is not part of the tabbed navigation and accessible by both view 1 and 2.

How do I go about changing the label of a UITabBarItem from the settings view with a text field. You can change a UITabBarItem by setTitle, but I don't know how to set up the delegation.

To give you perspective, View 1 and View 2 are actually Player 1 and Player 2. I want to give the user the option to change the PLayer 1 and PLayer 2 labels to their actual names via the settings screen.

Thanks in advance!

Upvotes: 0

Views: 537

Answers (1)

M.C.
M.C.

Reputation: 1745

Add the following code in the Settings View Controller (that is presented modally) and call it when you need to change the text field of one of the tabbaritems.

UITabBarController  *tabBarController =(UITabBarController *)[self presentingViewController];
NSArray *tabBarItems =[tabBarController.tabBar items];
UITabBarItem *barItem1=[tabBarItems objectAtIndex:0 ]; // or 1
barItem1.title=@"NewName";

Upvotes: 1

Related Questions