标签:
#import "HomePageViewController.h"
#import "InformationViewController.h"
#import "PublishViewController.h"
#import "FriendsViewController.h"
#import "MyViewController.h"
#import "LoginViewController.h"
@interface BaseTabBarController : UITabBarController<UITabBarControllerDelegate,UIActionSheetDelegate>
{
UINavigationController *navLogin0;
UINavigationController *navLogin1;
UINavigationController *navLogin2;
UINavigationController *navLogin3;
UINavigationController *navLogin4;
}
@end
- (void)viewDidLoad
{
[super viewDidLoad];
//主页
HomePageViewController *aHomePageViewController=[[HomePageViewController alloc]init];
UITabBarItem *item0=[[UITabBarItem alloc]initWithTitle:@"主页" image:[[UIImage imageNamed:@"icon_home1.png"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] selectedImage:[[UIImage imageNamed:@"icon_home2.png"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];
[item0 setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:BLACKCOLOR,NSForegroundColorAttributeName,[UIFont systemFontOfSize:12],NSFontAttributeName, nil] forState:UIControlStateSelected];
[item0 setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:GRAYCOLOR,NSForegroundColorAttributeName,[UIFont systemFontOfSize:12],NSFontAttributeName, nil] forState:UIControlStateNormal];
aHomePageViewController.tabBarItem=item0;
UINavigationController *nav0=[[UINavigationController alloc]initWithRootViewController:aHomePageViewController];
navLogin0=nav0;
//消息
InformationViewController *aInformationViewController=[[InformationViewController alloc]init];
UITabBarItem *item1=[[UITabBarItem alloc]initWithTitle:@"消息" image:[[UIImage imageNamed:@"icon_message1.png"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] selectedImage:[[UIImage imageNamed:@"icon_message2.png"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];
[item1 setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:BLACKCOLOR,NSForegroundColorAttributeName,[UIFont systemFontOfSize:12],NSFontAttributeName, nil] forState:UIControlStateSelected];
[item1 setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:GRAYCOLOR,NSForegroundColorAttributeName,[UIFont systemFontOfSize:12],NSFontAttributeName, nil] forState:UIControlStateNormal];
aInformationViewController.tabBarItem=item1;
UINavigationController *nav1=[[UINavigationController alloc]initWithRootViewController:aInformationViewController];
navLogin1=nav1;
//发布
PublishViewController *aPublishViewController=[[PublishViewController alloc]init];
UITabBarItem *item2=[[UITabBarItem alloc]initWithTitle:@"发布" image:[[UIImage imageNamed:@"icon_publish2.png"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] selectedImage:[[UIImage imageNamed:@"icon_publish1.png"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];
[item2 setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:BLACKCOLOR,NSForegroundColorAttributeName,[UIFont systemFontOfSize:12],NSFontAttributeName, nil] forState:UIControlStateSelected];
[item2 setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:GRAYCOLOR,NSForegroundColorAttributeName,[UIFont systemFontOfSize:12],NSFontAttributeName, nil] forState:UIControlStateNormal];
aPublishViewController.tabBarItem=item2;
UINavigationController *nav2=[[UINavigationController alloc]initWithRootViewController:aPublishViewController];
navLogin2=nav2;
//朋友
FriendsViewController *aFriendsViewController=[[FriendsViewController alloc]init];
UITabBarItem *item3=[[UITabBarItem alloc]initWithTitle:@"朋友" image:[[UIImage imageNamed:@"icon_friend1.png"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] selectedImage:[[UIImage imageNamed:@"icon_friend2.png"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];
[item3 setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:BLACKCOLOR,NSForegroundColorAttributeName,[UIFont systemFontOfSize:12],NSFontAttributeName, nil] forState:UIControlStateSelected];
[item3 setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:GRAYCOLOR,NSForegroundColorAttributeName,[UIFont systemFontOfSize:12],NSFontAttributeName, nil] forState:UIControlStateNormal];
aFriendsViewController.tabBarItem=item3;
UINavigationController *nav3=[[UINavigationController alloc]initWithRootViewController:aFriendsViewController];
navLogin3=nav3;
//我的
MyViewController *aMyViewController=[[MyViewController alloc]init];
UITabBarItem *item4=[[UITabBarItem alloc]initWithTitle:@"我的" image:[[UIImage imageNamed:@"icon_wo1.png"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] selectedImage:[[UIImage imageNamed:@"icon_wo2.png"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];
[item4 setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:BLACKCOLOR,NSForegroundColorAttributeName,[UIFont systemFontOfSize:12],NSFontAttributeName, nil] forState:UIControlStateSelected];
[item4 setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:GRAYCOLOR,NSForegroundColorAttributeName,[UIFont systemFontOfSize:12],NSFontAttributeName, nil] forState:UIControlStateNormal];
aMyViewController.tabBarItem=item4;
UINavigationController *nav4=[[UINavigationController alloc]initWithRootViewController:aMyViewController];
navLogin4=nav4;
self.viewControllers = [NSArray arrayWithObjects:nav0,nav1,nav2,nav3,nav4,nil];
self.delegate=self;
self.tabBar.backgroundColor = [UIColor clearColor];
}
3.
- (BOOL)tabBarController:(UITabBarController *)tabBarController shouldSelectViewController:(UIViewController *)viewController{
if ([[NSUserDefaults standardUserDefaults]objectForKey:@"userid"]) {
//已经登陆
}
else
{
//用户没登陆
if (viewController!=navLogin0)
{
UIActionSheet* mySheet = [[UIActionSheet alloc]
initWithTitle:nil
delegate:self
cancelButtonTitle:@"取消"
destructiveButtonTitle:nil
otherButtonTitles:@"去绑定社交账号登录",nil];
mySheet.tag=3000;
[mySheet showInView:self.view];
}
//这儿设置成YES 就会先跳到下个页面 然后弹出UIActionSheet 设置成NO 就会在当前页面 弹出UIActionSheet
return NO;
}
return YES;
}
- (void)actionSheetCancel:(UIActionSheet *)actionSheet{
//
}
- (void) actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex{
if (actionSheet.tag==3000) {
//登录按钮
if (buttonIndex==0) {
NSLog(@"denglu");
//用户没登陆
LoginViewController * detailViewController = [[LoginViewController alloc] init];
detailViewController.hidesBottomBarWhenPushed=YES;
[[self.viewControllers objectAtIndex:0] pushViewController:detailViewController animated:NO];
[actionSheet dismissWithClickedButtonIndex:0 animated:YES];
}
}
}
-(void)actionSheet:(UIActionSheet *)actionSheet didDismissWithButtonIndex:(NSInteger)buttonIndex{
//
}
-(void)actionSheet:(UIActionSheet *)actionSheet willDismissWithButtonIndex:(NSInteger)buttonIndex{
//
}
标签:
原文地址:http://www.cnblogs.com/huangzs/p/4472597.html