iPhone:我们可以在视图基础应用程序中使用选项卡栏控制器吗

发布于 2024-10-08 23:42:01 字数 70 浏览 2 评论 0 原文

我们可以在视图基本应用程序中使用UITab栏控制器吗?谢谢

can we use UITab bar controller in view base application thank you

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

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

发布评论

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

评论(2

忱杏 2024-10-15 23:42:01

是的,你可以。

你可以看看苹果提供的“TheElements”示例。
您可以在这里找到它:

https://developer.apple。 com/library/ios/#samplecode/TheElements/Introduction/Intro.html

查看应用程序委托。
这是一个非常直接的例子。

对于您的要求,我尝试做一个简单的例子:

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

    [self setupPortraitUserInterface];

    return YES;
}



- (UINavigationController *)AchievementsControllerWrappingViewController:(NSInteger*)tabIndex{

switch(tabIndex){
case 0:
    FirstViewController *theViewController;
    theViewController = [[FirstViewController alloc] init];
   break;

case 1:
    SecondViewController *theViewController;
    theViewController = [[SecondViewController alloc] init];
   break;
}

   UINavigationController *theNavigationController;
   theNavigationController = [[UINavigationController alloc] initWithRootViewController:theViewController];
    [theViewController release];

    return theNavigationController;

}



- (void)setupPortraitUserInterface {


    UINavigationController *localNavigationController;

    UIWindow *localWindow;
    localWindow = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    self.window = localWindow;

    [localWindow release];


    tabBarController = [[UITabBarController alloc] init];

    NSMutableArray *localViewControllersArray = [[NSMutableArray alloc] initWithCapacity:2];

    for(int i=0;i<2;i++){

    localNavigationController = [self AchievementsControllerWrappingViewController:i];
    [localViewControllersArray addObject:localNavigationController];
    [localNavigationController release];

    }

    tabBarController.viewControllers = localViewControllersArray;
    [localViewControllersArray release];

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


}

我不在 xCode 旁边,我是通过文本编辑完成的,所以请在使用时检查它。

沙尼

Yes you can.

you can look at the "TheElements" example that apple provides.
you can find it here:

https://developer.apple.com/library/ios/#samplecode/TheElements/Introduction/Intro.html

look at the app delegate.
its very strait forward example.

for you request i tried to make a simple example:

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

    [self setupPortraitUserInterface];

    return YES;
}



- (UINavigationController *)AchievementsControllerWrappingViewController:(NSInteger*)tabIndex{

switch(tabIndex){
case 0:
    FirstViewController *theViewController;
    theViewController = [[FirstViewController alloc] init];
   break;

case 1:
    SecondViewController *theViewController;
    theViewController = [[SecondViewController alloc] init];
   break;
}

   UINavigationController *theNavigationController;
   theNavigationController = [[UINavigationController alloc] initWithRootViewController:theViewController];
    [theViewController release];

    return theNavigationController;

}



- (void)setupPortraitUserInterface {


    UINavigationController *localNavigationController;

    UIWindow *localWindow;
    localWindow = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    self.window = localWindow;

    [localWindow release];


    tabBarController = [[UITabBarController alloc] init];

    NSMutableArray *localViewControllersArray = [[NSMutableArray alloc] initWithCapacity:2];

    for(int i=0;i<2;i++){

    localNavigationController = [self AchievementsControllerWrappingViewController:i];
    [localViewControllersArray addObject:localNavigationController];
    [localNavigationController release];

    }

    tabBarController.viewControllers = localViewControllersArray;
    [localViewControllersArray release];

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


}

i am not next to xCode and i did it with text edit, so please check it when you use it.

shani

左耳近心 2024-10-15 23:42:01

是的,我们可以..
为此,您必须创建 UITabBarViewController 及其对象,然后与您的 Application..like 一起引用它:

在实现文件的 ApplicationDidFinish Launching 中的 AppDelegate.h 中

@interface youAppDelegate.h : UIApplicationDelegate {
     UIWindow *window;
     YourViewController *viewController;
     // Declare Your TabBarController Here
     UITabBarController *tabBar;
}
@property (nonautomic, retain) IBOutlet UIWindow *window;
@property (nonautomic, retain) IBOutlet TabBarViewController *tabBar;

@end

添加以下代码

viewController = [[YourViewController alloc] init];
[viewController addSubView:tabBar];
[self.window addSubView:viewController];

在界面生成器中,您必须将 TabBarController 添加到 MainWindow 并将其关联与 IBOutLet。给出您想要在 tabBar 中显示的视图。

享受..

Yes we can..
For that you have to create UITabBarViewController and its Object then refrence it with you Application..like :

in your AppDelegate.h

@interface youAppDelegate.h : UIApplicationDelegate {
     UIWindow *window;
     YourViewController *viewController;
     // Declare Your TabBarController Here
     UITabBarController *tabBar;
}
@property (nonautomic, retain) IBOutlet UIWindow *window;
@property (nonautomic, retain) IBOutlet TabBarViewController *tabBar;

@end

in you implementation file's ApplicationDidFinish Launching add the following Code

viewController = [[YourViewController alloc] init];
[viewController addSubView:tabBar];
[self.window addSubView:viewController];

In interface builder you have to add the TabBarController to your MainWindow and relate it with the IBOutLet. Give what ever view you want to display in tabBar.

enjoy..

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文