UITabBarController - 不显示视图

发布于 2024-12-08 09:35:44 字数 1277 浏览 0 评论 0原文

我正在使用 UITabBarController 创建 iPhone 应用程序。
我想要实现的是,当我点击选项卡栏上的某些项目时,我不希望它们激活新视图,而是希望它们在当前视图中运行某些功能。 例如,我有一个地图处于活动状态的视图,当我单击选项卡栏上的某个项目时,我希望它能够找到地图上的当前位置。
我不知道使用 UITabBarController 是否是最好的解决方案。我还希望 1 个项目在 2 个视图(地图/列表)之间交换。
在底部使用某种工具栏或完全不同的东西会更好吗?
我认为不需要任何代码,但我创建了一个 UITabBarViewController 应用程序,并且创建了一个如下所示的 UITabBarControllerDelegate:

@interface MainTabBarControllerDelegate : NSObject <UIApplicationDelegate, UITabBarControllerDelegate> {
    UIWindow *window;
    UITabBarController *tabBarController;
}

@property (nonatomic, retain) IBOutlet UIWindow *window;
@property (nonatomic, retain) IBOutlet UITabBarController *tabBarController;

@end

@implementation MainTabBarControllerDelegate

@synthesize tabBarController, window;

- (void)applicationDidFinishLaunching:(UIApplication *)application
{
    tabBarController.delegate = self;
    [window addSubview:tabBarController.view];
}

- (BOOL)tabBarController:(UITabBarController *)tabBarController shouldSelectViewController:(UIViewController *)viewController{
    return YES;
}

- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController{

}

@end

我不知道如何实现该功能。 谢谢。

I'm creating an iPhone app with UITabBarController.
What I want to achieve is that when I tap some items on tabbar I don't want them to activate new view, instead of it I want them to run some functionality in the current view.
For example I have a view with map active and when I click some item on tabbar I want it to locate the current position on the map.
I don't know if using UITabBarController is the best solution for this. I'll also want 1 item to swap between 2 views (map / list).
Would it be better to use some kind of ToolBar on bottom or anything completely different?
I don't think there is any code needed, but I've got a UITabBarViewController app created and I created a UITabBarControllerDelegate like this:

@interface MainTabBarControllerDelegate : NSObject <UIApplicationDelegate, UITabBarControllerDelegate> {
    UIWindow *window;
    UITabBarController *tabBarController;
}

@property (nonatomic, retain) IBOutlet UIWindow *window;
@property (nonatomic, retain) IBOutlet UITabBarController *tabBarController;

@end

and

@implementation MainTabBarControllerDelegate

@synthesize tabBarController, window;

- (void)applicationDidFinishLaunching:(UIApplication *)application
{
    tabBarController.delegate = self;
    [window addSubview:tabBarController.view];
}

- (BOOL)tabBarController:(UITabBarController *)tabBarController shouldSelectViewController:(UIViewController *)viewController{
    return YES;
}

- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController{

}

@end

But I don't know how to achieve the functionality.
Thanks.

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

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

发布评论

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

评论(1

鹿! 2024-12-15 09:35:44

你是对的,你不需要 UITabBarController 为此。 UIToolbar 或您自己的自定义 UIView 就足够了。但如果您想使用 UITabBarController,则必须覆盖其通常的功能:

- (BOOL)tabBarController:(UITabBarController *)tabBarController shouldSelectViewController:(UIViewController *)viewController{
return NO; //do not select any view controller here
}

- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController{
  // find which tab was tapped here and handle the map's current position 
  // location operation accordingly
}

您还可以参考 此链接了解更多提示...

You're right, you don't need a UITabBarController for this. A UIToolbar or your own custom UIView would be enough. But if you want to use UITabBarController, you'll have to override its usual functioning:

- (BOOL)tabBarController:(UITabBarController *)tabBarController shouldSelectViewController:(UIViewController *)viewController{
return NO; //do not select any view controller here
}

- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController{
  // find which tab was tapped here and handle the map's current position 
  // location operation accordingly
}

You can also refer to this link for more tips...

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