如何识别标签栏项目?
我想知道如何识别标签栏中的项目?
我有一个包含 NAvigationController 的 tabBarController,如下所示:
NSMutableArray *localViewControllersArray = [[NSMutableArray alloc] initWithCapacity:6];
每个 navigationController 都位于该数组内。
我使用以下方法管理每个选项卡栏项目中的操作:
- tabBarController:(UITabBarController*)tabBarController didSelectViewController:(UIViewController*)viewController
我在这种方法中,即:
if (viewController == [self.tabBarController.viewControllers objectAtIndex:0])
像这样,我识别我单击的选项卡栏项目。
但问题是你可以在iphone屏幕中编辑Tabbar(因为数组中有6个viewControllers初始化tabbar)然后,我使用的方式是不正确的,因为我可以改变viewcontrollers的位置当我使用此编辑工具时在选项卡栏中。
谢谢
I would like to know how can I identify the items in the tab bar?
I have a tabBarController that contain NAvigationController like this:
NSMutableArray *localViewControllersArray = [[NSMutableArray alloc] initWithCapacity:6];
Each navigationController is inside this array.
I manage the actions in each tab bar item with the method:
- tabBarController:(UITabBarController*)tabBarController didSelectViewController:(UIViewController*)viewController
And I in this method, i.e.:
if (viewController == [self.tabBarController.viewControllers objectAtIndex:0])
Like this i identify wich tab bar item i click on.
BUT the problem is that you can edit the Tabbar in the iphone screen (because there are 6 viewControllers in the array that initialize the tabbar) and then, the way that i'm using is incorrect,because i can change the position of the viewcontrollers in the tabbar when i use this edit tool.
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
但是,我正在创建这样的 ViewController:(然后我无法进行#define,或输入不同的名称)
(UINavigationController *)createNavigationControllerWrappingViewControllerForDataSourceOfClass:(Class)datasourceClass {
}
(void)setupPortraitUserInterface {
}
But, I'm creating the ViewControllers like this: (then i cannot make #define, or put different names)
(UINavigationController *)createNavigationControllerWrappingViewControllerForDataSourceOfClass:(Class)datasourceClass {
}
(void)setupPortraitUserInterface {
}
您可以使用
UITabBarItem
的 tag 属性为每个UITabBarItem
提供唯一的数字标识符,然后进行比较。示例:
您可以记住指向每个
navigationControllers
的指针,并将它们与viewController
参数进行比较。示例:
您可以禁止在
UITabBarController
上进行编辑(将空数组或nil
传递给控制器的customizedViewControllers
属性)。例子:
You can use the
UITabBarItem
's tag property to give eachUITabBarItem
a unique numerical identifier, then compare that.Example:
You can remember pointers to each of your
navigationControllers
and compare those against theviewController
parameter.Example:
You can disallow editing on your
UITabBarController
(pass an empty array ornil
to the controller'scustomizableViewControllers
property).Example:
为此,我从 Elements 演示开始。 在该演示中,每个数据源都有自己的覆盖名称。 然后,每当我需要为特定选项卡执行某些操作(因为它具有与其他选项卡不同的数据源)时,在我的主导航控制器中,我会执行以下操作:
To do this, I started off with the Elements demo. In that demo, each datasource has it's own overridden name. Then any time I need to do something for a specific tab (because it's got a different datasource than other tabs), in my main navigation controller, I do: