iphone - 在 Objective-c 中以编程方式将底部栏设置为选项卡栏

标签 iphone objective-c ios

在 IB 中,我可以将底部栏设置为 View 的标签栏,如下图所示,但是如何通过 implement(.m) 文件中的代码设置它?

谢谢

enter image description here

最佳答案

为您要使用的 UIViewController 创建一个 NSArray。然后实例化一个 UITabBarController 并将 viewControllers 属性设置为该数组。然后将 tabBarControllerview 添加到窗口中。所有这些都应该在 AppDelegate.m 文件中完成。例如:

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

    UIViewController *vc1 = [[UIViewController alloc] init];
    UIViewController *vc2 = [[UIViewController alloc] init];
    CustomViewController *vc3 = [[CustomViewController alloc] init];

    NSArray *viewControllers = [NSArray arrayWithObjects:vc1, vc2, vc3, nil];
    [vc1 release]; [vc2 release]; [vc3 release];

    UITabBarController *tabBarController = [[UITabBarController alloc] init];
    [tabBarController setViewControllers:viewControllers];

    [window addSubview:[tabBarController view]];
    [window makeKeyAndVisible];

    return YES;
}

关于iphone - 在 Objective-c 中以编程方式将底部栏设置为选项卡栏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8663864/

相关文章:

ios - UIActivityViewController Gmail 共享主题和正文变空了吗?

iphone - 将渐变层添加到分组的 UITableViewCell 时出现框架问题

objective-c - 使用 ARC、lifetime qualifier assign 和 unsafe_unretained

objective-c - 如何隐藏 AVFoundation 调试日志?

ios - 使用 ALAssetLibrary 获取照片库中图像的时间戳

iphone - 显示带逗号的整数 : 30000 --> 30, 000

iphone - UIWebView加载本地内容延迟

iphone - Objective-C内存管理问题,NSMutableArray

写入右声道时 iOS AudioUnit 垃圾输入和输出回调错误

ios - 如何使用 AFNetworking API 编写 xml 响应