您的位置:首页 > 其它

获取TabbarController中点击item事件

2016-03-06 00:00 134 查看
摘要: 获取TabbarController中点击item事件



获取TabbarController中点击item事件的方法

只需要在TabbarController里实现这个代理方法

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

NSLog(@"%@",item.title);
}

然后你可以通过字符串title的判断

就可以知道将要显示的是哪个控制器

tabbar属性设置

/// 设置 tabbar
- (void)abountTabbar {

//新闻
XNNewsController *news = [XNNewsController newsControllerLoadXib];

[self addChildViewController:news imageName:@"tabbar_home" title:@"新闻"];

//本地
XNHereController *ereCtrl = [XNHereController hereControllerLoadXib];

[self addChildViewController:ereCtrl imageName:@"tabbar_message_center" title:@"本地"];

// 爆料
XNExplodeDataController *explodeCtrl = [XNExplodeDataController explodeDataControllerLoadXib];

[self addChildViewController:explodeCtrl imageName:@"tabbar_discover" title:@"爆料"];

// 我的
XNMyViewController *myCtrl = [XNMyViewController myViewControllerLoadXib];

[self addChildViewController:myCtrl imageName:@"tabbar_profile" title:@"我的"];
}

// 添加子控制器,并设置标题与图片
- (void)addChildViewController:(UIViewController *)childCtrl imageName:(NSString *)imageName title:(NSString *)title{

childCtrl.tabBarItem.image = [[UIImage imageNamed:imageName] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];

childCtrl.tabBarItem.selectedImage = [[UIImage imageNamed:[NSString stringWithFormat:@"%@_selected",imageName]] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];

//设置标题
childCtrl.tabBarItem.title = title;

//指定一下属性
NSMutableDictionary *dic = [NSMutableDictionary dictionary];

// 指定选中状态下文字颜色
dic[NSForegroundColorAttributeName] = [UIColor colorWithRed:0.835 green:0.090 blue:0.125 alpha:1.000];

[childCtrl.tabBarItem setTitleTextAttributes:dic forState:UIControlStateSelected];

[self addChildViewController:childCtrl];

}


学自这个网址的回答:
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: