UITabBarController - 不显示视图
我正在使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你是对的,你不需要
UITabBarController
为此。UIToolbar
或您自己的自定义UIView
就足够了。但如果您想使用UITabBarController
,则必须覆盖其通常的功能:您还可以参考 此链接了解更多提示...
You're right, you don't need a
UITabBarController
for this. AUIToolbar
or your own customUIView
would be enough. But if you want to useUITabBarController
, you'll have to override its usual functioning:You can also refer to this link for more tips...