简体   繁体   English

选项卡栏项目上的选项卡栏控制器情节提要单击事件

[英]Tab Bar Controller Storyboard click event on tab bar item

I have a Tab Bar Controller in Storyboard, connected with 2 views. 我在Storyboard中有一个Tab Bar Controller,与2个视图相连。 In View 2 (TimelineView) I had set in .h file: 在View 2(TimelineView)中,我在.h文件中进行了设置:

@interface Timeline_Overview : UIViewController<UITabBarDelegate>{
}
@property (nonatomic, retain) IBOutlet UITabBarItem *PostImage;

And in .m file: 并在.m文件中:

-(void)tabBar:(UITabBar *)tabBar didSelectItem:(UITabBarItem *)item
{

NSLog(@"test");
if(item.tag==2)
{

    UIStoryboard *mainStoryboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
    UITabBarController *TimeLine = [mainStoryboard instantiateViewControllerWithIdentifier:@"Post_Photo_One"];
    [self presentViewController:TimeLine animated:YES completion:nil];
}
else
{
    //your code
}
}

but this void does not fire :( 但是这个虚空不会触发:(

Here is a pic from storyboard: 这是情节提要中的图片: 故事板

Can anybody help? 有人可以帮忙吗?

EDIT: 编辑:

here is my inspection It looks like yours and it does not work :( 这是我的检查看起来像您的检查,它不起作用:(

在此处输入图片说明

EDIT 2: 编辑2:

Here my Storyboard, I have set the Custom Class to my "Timeline_Overview" from the "Post Image" tab but it does not work :( 在我的情节提要中,我已将“自定义类”从“发布图像”选项卡设置为我的“ Timeline_Overview”,但它不起作用:( 在此处输入图片说明

Change in the connection inspector the delegate of the UITabBarController delegate in the storyboard to your relevant class, see screenshot: storyboard UITabBarController中的UITabBarController delegate的连接检查器的委托更改为您的相关类,请参见屏幕截图:

在此处输入图片说明

and Don't forget to change the identity inspector to your custom tab bar: 并且不要忘记将身份检查器更改为自定义标签栏:

在此处输入图片说明

If you are using storyboard, do this 如果您使用情节提要,请执行此操作

in didFinishLaunchingWithOptions 在didFinishLaunchingWithOptions中

UITabBarController *tabBar = (UITabBarController *)self.window.rootViewController;
[tabBar setDelegate:self];

Also in AppDelegate, keep <UITabBarControllerDelegate> 同样在AppDelegate中,保留<UITabBarControllerDelegate>

And then 接着

-(void) tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController
{
   //Write your code here
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM