アプリ内の言語切り替えで、TabBar の MoreViewController のビューにアクセスして、タイトルを変更する必要があります。
誰かがそれを行う方法を教えてもらえますか?
あなたの助けに感謝します。
列
次のコードを使用して、6番目のView Controller(moreリストの最後のもの)のtabBarアイテムの1つのタイトルを変更できました。
NSArray *vcs = [(UITabBarController *)self.window.rootViewController viewControllers];
[[vcs.lastObject tabBarItem] setTitle:@"New Title"];
これはあなたがやりたいことですか?
編集後: 最初の設定後にこれらのタイトルを変更するには、tabBar コントローラーの viewControllers プロパティを再設定する必要があります。このコード例では、6 番目のビュー コントローラーのボタンを、3 つのコントローラーのタイトルを変更するアクション メソッドに接続しました。2 つは more リストにあり、1 つは通常リストにあります。
-(IBAction)changeNames:(id)sender {
UITabBarController *tbc = (UITabBarController *)[[UIApplication sharedApplication] delegate].window.rootViewController;
NSArray *vcs = tbc.viewControllers;
[[vcs.lastObject tabBarItem] setTitle:@"New Title"];
[[[vcs objectAtIndex:4] tabBarItem] setTitle:@"New VC"];
[[[vcs objectAtIndex:3] tabBarItem] setTitle:@"New VC2"];
tbc.viewControllers = tbc.viewControllers;
}
ここにあなたのために働くかもしれないいくつかのスニペットがあります. 以下のすべては、すべての新しい iOS リリースで中断される可能性があることに注意してください。
ユーザーが編集中のタイトルと同様に、詳細ビューのタイトルをカスタマイズします。
- (void)customizeTitleViewWithNavigationItem:(UINavigationItem *)navigationItem
{
VASSERT(navigationItem != nil, @"invalid navigationItem supplied", navigationItem);
UILabel *titleView = [[UILabel alloc] initWithFrame:CGRectZero];
titleView.backgroundColor = [UIColor clearColor];
titleView.font = [UIFont boldSystemFontOfSize:20.0f];
titleView.text = navigationItem.title;
[titleView sizeToFit];
navigationItem.titleView = titleView;
[titleView release];
}
UINavigationController
これはのデリゲート内で実装する必要があります。
- (void)navigationController:(UINavigationController *)navigationController
willShowViewController:(UIViewController *)viewController
animated:(BOOL)animated
{
if (navigationController == tabBarController_.moreNavigationController)
{
if ([viewController isKindOfClass:NSClassFromString(@"UIMoreListController")])
{
[self customizeTitleViewWithNavigationItem:viewController.navigationItem];
}
else
{
NSLog(@"viewController (%@) does not seem to be a UIMoreListController", viewController);
}
}
else
{
NSLog(@"navigationController (%@) does not seem to be the moreNavigationController", navigationController);
}
}
UITabBarController
これはのデリゲート内で実装する必要があります。
- (void)tabBarController:(UITabBarController *)controller willBeginCustomizingViewControllers:(NSArray *)viewControllers
{
//get the second view of the upcoming tabbar-controller
UIView *editView = [controller.view.subviews objectAtIndex:1];
//did we get what we expected, which is a UITabBarCustomizeView?
if (editView != nil && [editView isKindOfClass:NSClassFromString(@"UITabBarCustomizeView")])
{ //yes->get the navigation-view
UIView *navigationView = [editView.subviews objectAtIndex:0];
//is that a navigationBar?
if (navigationView != nil && [navigationView isKindOfClass:[UINavigationBar class]])
{ //yes->...
UINavigationBar *navigationBar = (UINavigationBar *)navigationView;
[self customizeTitleViewWithNavigationItem:navigationBar.topItem];
}
else
{
NSLog(@"the navigationView (%@) does not seem to be a navigationBar", navigationView);
}
}
else
{
NSLog(@"the editView (%@) does not seem to be a UITabBarCustomizeView", editView);
}
}