如何以编程方式设置标签栏项目的标题?

发布于 2024-12-29 09:01:14 字数 978 浏览 0 评论 0原文

我尝试了这个,但它不起作用,我看不到选项卡栏项目。我该如何解决这个问题?感谢您的帮助。

- (void)viewDidLoad
{
[super viewDidLoad];
 // Do any additional setup after loading the view from its nib.

 myTabBarController = [[UITabBarController alloc] init];        
 tab1 = [[ZiyaretFormTab1 alloc] initWithNibName:@"ZiyaretFormTab1" bundle:nil];   
 tab2 = [[ZiyaretFormTab2 alloc] initWithNibName:@"ZiyaretFormTab2" bundle:nil];   
 tab3 = [[ZiyaretFormTab3 alloc] initWithNibName:@"ZiyaretFormTab3" bundle:nil];  
 tab4 = [[ZiyaretFormTab4 alloc] initWithNibName:@"ZiyaretFormTab4" bundle:nil];    
 tab5 = [[ZiyaretFormTab5 alloc] initWithNibName:@"ZiyaretFormTab5" bundle:nil];  

 myTabBarController.viewControllers = [NSArray arrayWithObjects: tab1,    tab2,tab3,tab4,tab5,nil]; 
 UITabBarItem *tabItem = [[[myTabBarController tabBar] items] objectAtIndex:1];
 [tabItem setTitle:@"theTitle"];

 [self.view addSubview:myTabBarController.view];    
 myTabBarController.selectedIndex=0;

}

I try this but it not works I can not see tab bar item..How can I solve this problem? Thanks for your help.

- (void)viewDidLoad
{
[super viewDidLoad];
 // Do any additional setup after loading the view from its nib.

 myTabBarController = [[UITabBarController alloc] init];        
 tab1 = [[ZiyaretFormTab1 alloc] initWithNibName:@"ZiyaretFormTab1" bundle:nil];   
 tab2 = [[ZiyaretFormTab2 alloc] initWithNibName:@"ZiyaretFormTab2" bundle:nil];   
 tab3 = [[ZiyaretFormTab3 alloc] initWithNibName:@"ZiyaretFormTab3" bundle:nil];  
 tab4 = [[ZiyaretFormTab4 alloc] initWithNibName:@"ZiyaretFormTab4" bundle:nil];    
 tab5 = [[ZiyaretFormTab5 alloc] initWithNibName:@"ZiyaretFormTab5" bundle:nil];  

 myTabBarController.viewControllers = [NSArray arrayWithObjects: tab1,    tab2,tab3,tab4,tab5,nil]; 
 UITabBarItem *tabItem = [[[myTabBarController tabBar] items] objectAtIndex:1];
 [tabItem setTitle:@"theTitle"];

 [self.view addSubview:myTabBarController.view];    
 myTabBarController.selectedIndex=0;

}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

蛮可爱 2025-01-05 09:01:14

在进入选项卡的每个视图控制器(ZiyaretFormTab1 到 ZiyaretFormTab5)中,将此代码插入到 initWithNibviewDidLoad 函数中。

    UITabBarItem * tabtitle = [[UITabBarItem alloc] initWithTitle: @"title"
                                                            image: nil //or your icon 
                                                              tag: 0];

    [self setTabBarItem: tabtitle];

In each of your view controllers that go into the tabs (ZiyaretFormTab1 to ZiyaretFormTab5), insert this code into initWithNib or viewDidLoad functions.

    UITabBarItem * tabtitle = [[UITabBarItem alloc] initWithTitle: @"title"
                                                            image: nil //or your icon 
                                                              tag: 0];

    [self setTabBarItem: tabtitle];
离鸿 2025-01-05 09:01:14

选项卡栏标题由各自的视图控制器控制。设置标题的最简单方法是在该选项卡的视图控制器中,而不是尝试直接在选项卡中设置它。

每个视图控制器都有一个 title 属性,用于设置选项卡栏和导航栏中的标题。它还具有一个 tabBarItem 属性,该属性拥有自己的 title 属性,如果您只想设置选项卡而不影响导航栏,则可以设置该属性。

因此,在 viewController 的 viewDidLoad 中,您可以编写:

self.tabBarItem.title = @"theTitle";

Tab bar titles are controlled by their respective view controllers. The easiest way to set the title is from within the view controller for that tab, instead of trying to set it in the tab directly.

Each view controller has a title property which is used to set the title in tab bars and navigation bars. It also has a tabBarItem property which has it's own title property that you can set if you want to just set the tab and not affect navigation bars.

So in the viewDidLoad of your viewController, you could write:

self.tabBarItem.title = @"theTitle";
沧桑㈠ 2025-01-05 09:01:14

将选项卡设置放入 AppDelegate。

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions

把你的名字和制服图标信息访问这里:

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        self.title = @"Kulağını tersten tutmana gerek yok";
    self.tabBarItem.image = [UIImage imageNamed:@"ringtab.png"];

    }
    return self;
}

Put the tab settings to AppDelegate.

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions

Put your name and icon information uniforms visit here:

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        self.title = @"Kulağını tersten tutmana gerek yok";
    self.tabBarItem.image = [UIImage imageNamed:@"ringtab.png"];

    }
    return self;
}
心意如水 2025-01-05 09:01:14

您是否尝试

[tab1 setTitle:@"Your Title"]

在分配并初始化它之后进行设置?

Have you tried to set

[tab1 setTitle:@"Your Title"]

after allocating and initialising it.

赠佳期 2025-01-05 09:01:14
 UITabBarItem *item = [self.tabBarController.tabBar.items objectAtIndex:0];
 [item setTitle:@"fgfdgd"];  
 UITabBarItem *item = [self.tabBarController.tabBar.items objectAtIndex:0];
 [item setTitle:@"fgfdgd"];  
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文