码迷,mamicode.com
首页 > 其他好文 > 详细

“口袋郴州”项目总结-标签控制器

时间:2014-11-08 15:12:49      阅读:137      评论:0      收藏:0      [点我收藏+]

标签:http   io   color   ar   os   使用   sp   for   数据   

//
//  AppDelegate.m
//  KouDaiChenhZhou
//
//  Created by jishubumac on 14/11/7.
//  Copyright (c) 2014年 jishubumac. All rights reserved.
//

#import "AppDelegate.h"
#import "PublicHeader.h"
#import <ShareSDK/ShareSDK.h>


@interface AppDelegate ()<UITabBarDelegate>//引用协议
{
    UITabBarController *tabBarVCtrl;
    UITabBar *tabBar;
    SheQuViewController *SQVCtrl;
    ZhaoPinViewController*  ZPVCtrl;
    ViewController* VCtrl;
    YouPinViewController* YPVCtrl;
    TuanGouViewController* TGVCtrl;
}

@end

@implementation AppDelegate

- (void)createTabBar
{
    NSArray *images = @[@"shequ0.png",@"zhaopin0.png",@"shouye0.png",@"youpin0.png",@"tuangou0.png"];//@"shequ0.png",@"zhaopin0.png",@"shouye0.png",@"youpin0.png",@"tuangou0.png"
    NSArray *selectedImages = @[@"shequ1.png",@"zhaopin1.png",@"shouye1.png",@"youpin1.png",@"tuangou1.png"];
    NSArray *titleArray = @[@"社区",@"招聘",@"首页",@"优品",@"团购"];
    //@"shequ1.png",@"zhaopin1.png",@"shouye1.png",@"youpin1.png",@"tuangou1.png"
    NSMutableArray *itemsArray = [NSMutableArray array];
    for (int i = 0; i < 5; i++) {
        UIImage *image = [UIImage imageNamed:images[i]];
        UIImage *selectedImage = [UIImage imageNamed:selectedImages[i]];
        UITabBarItem *item = [[UITabBarItem alloc] initWithTitle:titleArray[i] image:image selectedImage:selectedImage];
        item.tag = i;
        [itemsArray addObject:item];
    }
    
    tabBar = [[UITabBar alloc] initWithFrame:tabBarVCtrl.tabBar.bounds];
    tabBar.items = itemsArray;
    tabBar.backgroundImage = [UIImage imageNamed:@"TabBarBackground.png"];
    tabBar.delegate = self;
    tabBar.selectedItem = itemsArray[2];
    //接受各个页面发送过来的selectIndex值,在选中该值对应的tabBarItem
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(recieveselectedIndex:) name:@"selectedIndex" object:nil];
    [tabBarVCtrl.tabBar addSubview:tabBar];
    
}

- (void)initializePlat
{
    // 4174c00f5cae
    //5c242eac125fe6b21a1bd4f508a9dabd
    //添加新浪微博应用 注册网址 http://open.weibo.com
    [ShareSDK connectSinaWeiboWithAppKey:@"4174c00f5cae"
                               appSecret:@"5c242eac125fe6b21a1bd4f508a9dabd"
                             redirectUri:@"http://www.sharesdk.cn"];
    //当使用新浪微博客户端分享的时候需要按照下面的方法来初始化新浪的平台
    [ShareSDK  connectSinaWeiboWithAppKey:@"4174c00f5cae"
                                appSecret:@"5c242eac125fe6b21a1bd4f508a9dabd"
                              redirectUri:@"http://www.sharesdk.cn"
                              weiboSDKCls:[WeiboSDK class]];
    
    //添加腾讯微博应用 注册网址 http://dev.t.qq.com
    [ShareSDK connectTencentWeiboWithAppKey:@"4174c00f5cae"
                                  appSecret:@"5c242eac125fe6b21a1bd4f508a9dabd"
                                redirectUri:@"http://www.sharesdk.cn"
                                   wbApiCls:[WeiboApi class]];
    
    //添加QQ空间应用  注册网址  http://connect.qq.com/intro/login/
    [ShareSDK connectQZoneWithAppKey:@"4174c00f5cae"
                           appSecret:@"5c242eac125fe6b21a1bd4f508a9dabd"
                   qqApiInterfaceCls:[QQApiInterface class]
                     tencentOAuthCls:[TencentOAuth class]];
    
    //添加QQ应用  注册网址  http://open.qq.com/
    [ShareSDK connectQQWithQZoneAppKey:@"4174c00f5cae"
                     qqApiInterfaceCls:[QQApiInterface class]
                       tencentOAuthCls:[TencentOAuth class]];
    
    //添加微信应用 注册网址 http://open.weixin.qq.com
    [ShareSDK connectWeChatWithAppId:@"wx4868b35061f87885"
                           appSecret:@"5c242eac125fe6b21a1bd4f508a9dabd"
                           wechatCls:[WXApi class]];
}


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    // Override point for customization after application launch.
    [ShareSDK registerApp:@"4174c00f5cae"];     //参数为ShareSDK官网中添加应用后得到的AppKey
    
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    self.window.backgroundColor = [UIColor whiteColor];
    [self.window makeKeyAndVisible];
    SQVCtrl = [[SheQuViewController alloc] init];
    UINavigationController *NavCtrl = [[UINavigationController alloc] initWithRootViewController:SQVCtrl];
    ZPVCtrl = [[ZhaoPinViewController alloc] init];
    UINavigationController *NavCtrl2 = [[UINavigationController alloc] initWithRootViewController:ZPVCtrl];
    
    VCtrl = [[ViewController alloc] init];
    UINavigationController *NavCtrl3 = [[UINavigationController alloc] initWithRootViewController:VCtrl];
    
    
    YPVCtrl = [[YouPinViewController alloc] init];
    UINavigationController *NavCtrl4 = [[UINavigationController alloc] initWithRootViewController:YPVCtrl];
    
    TGVCtrl = [[TuanGouViewController alloc] init];
    UINavigationController *NavCtrl5 = [[UINavigationController alloc] initWithRootViewController:TGVCtrl];
    
    tabBarVCtrl = [[UITabBarController alloc] init];
    tabBarVCtrl.viewControllers = @[NavCtrl,NavCtrl2,NavCtrl3,NavCtrl4,NavCtrl5];
    tabBarVCtrl.selectedIndex = 2;//初始化选中第二个
    tabBarVCtrl.tabBar.selectedImageTintColor = [UIColor greenColor];//设置tabBarItem选中时的字图颜色,iOS 8.0中没有该属性(若设置,会出现警告)
    self.window.rootViewController = tabBarVCtrl;
    
    [self createTabBar];
    [self initializePlat];//初始化平台
    return YES;
}

- (void)tabBar:(UITabBar *)tabBar didSelectItem:(UITabBarItem *)item
{
    tabBarVCtrl.selectedViewController = tabBarVCtrl.viewControllers[item.tag];
    //点击切换页面,并使选中的页面的webView重新加载主页
    switch (item.tag) {
        case 0:
            [SQVCtrl.webView loadRequest:[NSURLRequest requestWithURL:SQVCtrl.homeurl]];break;
        case 1:
            [ZPVCtrl.webView loadRequest:[NSURLRequest requestWithURL:ZPVCtrl.homeurl]];break;
        case 2:
            [VCtrl.webView loadRequest:[NSURLRequest requestWithURL:VCtrl.homeurl]];break;
        case 3:
            [YPVCtrl.webView loadRequest:[NSURLRequest requestWithURL:YPVCtrl.homeurl]];break;
        case 4:
            [TGVCtrl.webView loadRequest:[NSURLRequest requestWithURL:TGVCtrl.homeurl]];break;
        default:
            break;
    }
    
}

- (void)recieveselectedIndex:(NSNotification *)sender
{
    NSInteger currentIndex = [[sender object] intValue];//将字符串转化为基本数据类型,给currentIndex赋值
    tabBar.selectedItem = tabBar.items[currentIndex];//设置索引为currentIndex的tabBarItem为选中
}

 

“口袋郴州”项目总结-标签控制器

标签:http   io   color   ar   os   使用   sp   for   数据   

原文地址:http://www.cnblogs.com/z-j-w/p/4083325.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!