[英]UITabBarController - don't show the view
I'm creating an iPhone app with UITabBarController. 我正在使用UITabBarController创建一个iPhone应用程序。
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. 我不知道使用UITabBarController是否是对此的最佳解决方案。 I'll also want 1 item to swap between 2 views (map / list).
我还希望1个项目在2个视图(地图/列表)之间交换。
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: 我认为不需要任何代码,但是我创建了一个UITabBarViewController应用程序,并且创建了一个UITabBarControllerDelegate,如下所示:
@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.
谢谢。
You're right, you don't need a UITabBarController
for this. 没错,您不需要为此使用
UITabBarController
。 A UIToolbar
or your own custom UIView
would be enough. 一个
UIToolbar
或您自己的自定义UIView
就足够了。 But if you want to use UITabBarController
, you'll have to override its usual functioning: 但是,如果要使用
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 can also refer to this link for more tips... 您也可以参考此链接以获取更多提示...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.