IOS-トップページバナー修正

36880 ワード

種類:IndexAskDocctorView Manager.m関数:(void)udateView WithHttpObject:(id)htttpObject類:IndexAskdoctororViemoller.m関数:(void)parseHttpReResponse:(id)parsephttphttppResosososolipose:(id)名前:(idttttttttttttttttttttttttttttttttttttttttttttppppsdededededededededededededededededededededededededededelegate.m
作り方:ソースデータフォーマットを目標データに変換します.
1.データフォーマット
最初のページのデータ関数を読み込みます.
/** *          */
- (void) loadBannerAndPromotionFromMat {

    //       
    User* user = [[User alloc] init];
    [user loadFromFile];

    //     
    NSMutableDictionary* paras = [NSMutableDictionary dictionaryWithCapacity: 6];
    [paras setObject:user.matVersion forKey:@"version"];
    [paras setObject:@"" forKey:@"token"];
    [paras setObject:@"MSG_QUERY_SPREAD_INFO_REQ" forKey:@"msgType"];
    [paras setObject:[NSString stringWithFormat:@"%d",user.matMsgSeq] forKey:@"msgSeq"];
    [paras setObject:user.matAppType forKey:@"appType"];
    [paras setObject:user.uniqueDeviceToken forKey:@"IMEI"];

    NSLog(@"    (paras) - %@", paras);

    //     
    [[ChunyuAPIClient sharedClient] postPath:[ChunyuAPIClient MAT_NOAUTH_HTTP_URL]
                                  parameters:paras
                          requestContentType:kCYHttpRequestContentTypeJSON
                                     success:^(AFHTTPRequestOperation *operation, id responseObject) {
                                         NSLog(@"MSG_QUERY_SPREAD_INFO_REQ - %@: ", responseObject);
                                         NSLog(@"  : %@", responseObject[@"description"]);
                                         if ([responseObject[@"errorCode"] intValue] != 0) {
                                             [SVProgressHUD showErrorWithStatus : @"      "
                                                                       duration : 1.5f];
                                             return;
                                         }

                                         NSMutableArray* infos = responseObject[@"spreadInfoList"];
                                         NSMutableArray* banners = [[NSMutableArray alloc] init]; //   
                                         NSMutableArray* promotions = [[NSMutableArray alloc] init]; //    
                                         for (int i=0; i < infos.count; ++i) {
                                             NSMutableDictionary* obj = infos[i];
                                             if ([obj[@"infoLocation"] intValue] == 1) {
                                                 [banners addObject:obj];
                                             } else if ([obj[@"infoLocation"] intValue] == 2) {
                                                 [promotions addObject:obj];
                                             } else {
                                                 [SVProgressHUD showErrorWithStatus : @"        "
                                                                           duration : 1.5f];
                                             }
                                         }
                                         NSLog(@"Banner - %@", banners);
                                         NSLog(@"Promotion - %@", promotions);

                                         NSMutableArray* cyBanners = [[NSMutableArray alloc] init]; //   

                                         for (int i=0; i<banners.count; ++i) {
                                             NSMutableDictionary* obj = banners[i];
                                             NSMutableDictionary* cyObj = [self convertBannerFromMatToCYWithDict:obj];
                                             [cyBanners addObject:cyObj];
                                         }

                                         NSLog(@"CYBanner - %@", cyBanners);

                                         [[IndexAskDoctorBannerManager sharedInstance] updateBannerDataList: cyBanners];

                                         NSMutableDictionary* cyPromotions = [[NSMutableDictionary alloc]init];
                                         NSMutableArray* list1 = [[NSMutableArray alloc] init];
                                         NSMutableArray* list2 = [[NSMutableArray alloc] init];
                                         for (int i=0; i<promotions.count; ++i) {
                                             if (i<=1) {
                                                 [list1 addObject:promotions[i]];
                                             } else{
                                                 [list2 addObject:promotions[i]];
                                             }
                                         }
                                         [cyPromotions setObject:list1 forKey:@"list_1"];
                                         [cyPromotions setObject:list2 forKey:@"list_2"];

                                         NSLog(@"CYPromotion - %@", cyPromotions);

                                         [[IndexAskDoctorPromotionManager sharedInstance] updatePromotionData: cyPromotions];

                                         [self showModel: YES];
                                     }

                                     failure:^(AFHTTPRequestOperation *operation, NSError *error) {
                                         [SVProgressHUD showErrorWithStatus : CYDescriptionForError(error)
                                                                   duration : 1.5f];
                                     }];
}
ターゲットデータ:banerリスト(バナーの例データ):
( { "extra_info" = { }; image = "http://img.chunyu.mobi/media/images/2015/04/13/f729352f294b_w640_h210_.jpg"; "share_key" = "top_banner,413"; title = "Mall\Uff0d\U5b9d\U5b9d\U6e05\U6d01\U4ea7\U54c1"; type = vltr; url = "http://www.chunyuyisheng.com/mall/?category=bb_clean"; version = "5.0.0"; }, { "extra_info" = { "news_id" = 35789; }; image = "http://dn-chunyu.qbox.me/@/media/images/2015/07/04/e8dffa8eab3e_w640_h210_.jpg"; "share_key" = "top_banner,977"; title = "\U5973\U751f\U7684\U80f8\U771f\U7684\U4f1a\U201c\U6478\U6478\U5927\U201d\U5417\Uff1f"; type = news; url = ""; version = "5.0.0"; }, { "extra_info" = { }; image = "http://dn-chunyu.qbox.me/@/media/images/2015/06/10/69bd533303d9_w640_h210_.jpg"; "share_key" = "top_banner,335"; title = "mall\Uff0d\U4fdd\U5b81\U4e13\U573a\U7279\U5356"; type = vltr; url = "http://www.chunyuyisheng.com/mall/?category=bb_clean"; version = "5.0.0"; }, { "extra_info" = { "news_id" = 32798; }; image = "http://dn-chunyu.qbox.me/@/media/images/2015/06/29/aa6dba39f855_w640_h210_.jpg"; "share_key" = "top_banner,917"; title = "\U6700\U5168\U9003\U751f\U81ea\U6551\U6307\U5357\Uff0c\U5e0c\U671b\U4f60\U4e00\U8f88\U5b50\U90fd\U7528\U4e0d\U5230"; type = news; url = ""; version = "5.0.0"; }, { "extra_info" = { "news_id" = 34571; }; image = "http://dn-chunyu.qbox.me/@/media/images/2015/07/02/28f57c19cd94_w640_h210_.jpg"; "share_key" = "top_banner,956"; title = "\U9ad8\U9f84\U4ea7\U5987\U8981\U9762\U4e34\U7684N\U4e2a\U95ee\U9898"; type = news; url = ""; version = "5.0.0"; } )
topic_プロモーション(プロモーション例データ):
{
    "list_1" =     (
                {
            id = 2;
            "mini_image" = "http://img.chunyu.mobi/media/images/2014/12/15/61cf1a5a5ecd_w276_h147_.png";
            "promotion_type" = home;
            rank = 3;
            "share_key" = "topic_promotion,2";
            title = "\U5987\U79d1\U95ee\U9898\U968f\U65f6\U95ee";
            url = "http://www.chunyuyisheng.com/api/v5/topic_promotion/2/wap";
        },
                {
            id = 5;
            "mini_image" = "http://img.chunyu.mobi/media/images/2014/12/15/7806c983d7cf_w276_h147_.png";
            "promotion_type" = home;
            rank = 5;
            "share_key" = "topic_promotion,5";
            title = "\U5fc3\U7406\U54a8\U8be2\U5ba4";
            url = "http://www.chunyuyisheng.com/api/v5/topic_promotion/5/wap";
        },
                {
            id = 7;
            "mini_image" = "http://img.chunyu.mobi/media/images/2014/08/15/d11cb5319635_w300_h140_.png";
            "promotion_type" = home;
            rank = 7;
            "share_key" = "topic_promotion,7";
            title = "\U6574\U5f62\U7f8e\U5bb9\U6211\U60f3\U95ee";
            url = "http://www.chunyuyisheng.com/api/v5/topic_promotion/7/wap";
        }
    );
    "list_2" =     (
                {
            id = 3;
            "mini_image" = "http://img.chunyu.mobi/media/images/2014/12/15/aed31ede6a5a_w276_h147_.png";
            "promotion_type" = home;
            rank = 2;
            "share_key" = "topic_promotion,3";
            title = "\U76ae\U80a4\U95ee\U9898\U627e\U4e13\U5bb6";
            url = "http://www.chunyuyisheng.com/api/v5/topic_promotion/3/wap";
        },
                {
            id = 1;
            "mini_image" = "http://img.chunyu.mobi/media/images/2014/12/15/94536e14c6a6_w276_h147_.png";
            "promotion_type" = home;
            rank = 4;
            "share_key" = "topic_promotion,1";
            title = "\U5a74\U5e7c\U513f\U4e13\U5bb6";
            url = "http://www.chunyuyisheng.com/api/v5/topic_promotion/1/wap";
        },
                {
            id = 4;
            "mini_image" = "http://img.chunyu.mobi/media/images/2014/08/15/53d6b195278b_w300_h140_.png";
            "promotion_type" = home;
            rank = 6;
            "share_key" = "topic_promotion,4";
            title = "\U5173\U7231\U7537\U6027\U5065\U5eb7";
            url = "http://www.chunyuyisheng.com/api/v5/topic_promotion/4/wap";
        }
    );
}
ソースデータ:
{
    description = "\U6210\U529f";
    errorCode = 0;
    msgSeq = 10;
    msgType = "MSG_QUERY_SPREAD_INFO_RSP";
    spreadInfoList =     (
                {
            abstractInfo = "\U4e2d\U56fd\U79fb\U52a8\U627eTA";
            downloadUrl = "http://183.230.40.64:5090/filemanage/firmwareDownload/65cb5e341f57a544ebf4f33e38dedf03/3";
            id = 1;
            infoLocation = 2;
            redirectUrl = "http://detail.tmall.com/item.htm?spm=a1z10.3-b.w4011-9638551477.160.p1q0Vp&id=44600955548&rn=34efd7fada2ba27386fc62574b6b739b&abbucket=19";
            title = "\U201d\U627eTA\U201c";
        },
                {
            abstractInfo = "\U6570\U7801\U94a2\U7434 \U4f18\U96c5\U5178\U85cf";
            downloadUrl = "http://183.230.40.64:5090/filemanage/firmwareDownload/7f0b1e2dbb3d2e7dc092ac04f3254c7d/4";
            id = 2;
            infoLocation = 2;
            redirectUrl = "http://item.jd.com/1570506138.html";
            title = "The ONE\U667a\U80fd\U94a2\U7434";
        },
                {
            abstractInfo = "\U8bed\U97f3\U5bf9\U8bb2 \U4e91\U7aef\U5f55\U5236";
            downloadUrl = "http://183.230.40.64:5090/filemanage/firmwareDownload/180e84c8e18f6e21a9059e3a0a033b72/2";
            id = 3;
            infoLocation = 2;
            redirectUrl = "http://detail.tmall.com/item.htm?spm=a1z10.3-b.w4011-9638551477.80.p1q0Vp&id=42797928742&rn=34efd7fada2ba27386fc62574b6b739b&abbucket=19";
            title = "\U548c\U76ee WIFI\U4e91\U6444\U50cf\U5934";
        },
                {
            abstractInfo = "\U667a\U80fd\U5546\U54c1\U805a\U96c6\U5730";
            downloadUrl = "http://183.230.40.64:5090/filemanage/firmwareDownload/bd51e2fd1b424c16b38e7cf744cd2f91/1";
            id = 4;
            infoLocation = 2;
            redirectUrl = "http://www.zhipinmall.com/";
            title = "\U667a\U54c1\U5546\U57ce";
        },
                {
            abstractInfo = "\U8fd1\U51e0\U5e74\U6765,\U6211\U56fd\U533b\U836f\U536b\U751f\U5de5\U4f5c\U8005\U7ecf\U8fc7\U53cd\U590d\U7684\U4e34\U5e8a\U5b9e\U9a8c\U8bc1\U660e,\U8702\U871c\U5bf9\U5fc3\U810f\U75c5\U3001\U809d\U810f\U75c5\U3001\U9ad8\U8840\U538b\U3001\U80ba\U75c5\U3001\U773c\U75c5\U3001\U7cd6\U5c3f\U75c5\U3001\U75e2\U75be\U3001\U4fbf\U79d8\U3001\U8d2b\U8840\U3001\U80c3\U53ca\U5341\U4e8c\U6307\U80a0\U6e83\U75a1\U3001\U5173\U8282\U708e\U3001\U795e\U7ecf\U7cfb\U7edf\U75be\U75c5\U3001\U76ae\U80a4\U75c5\U3001\U70eb\U4f24\U3001\U51bb\U4f24\U7b49\U75c7\U90fd\U6709\U4e0d\U540c\U7a0b\U5ea6\U7684\U7597\U6548\U3002";
            downloadUrl = "http://183.230.40.64:5090/filemanage/firmwareDownload/e8fa7c68ca197c541669fbc6878b0437/j1";
            id = 19;
            infoLocation = 1;
            redirectUrl = "http://183.230.40.64/portal/adsmanager/viewAd?id=19";
            title = "\U6e05\U70ed\U6ecb\U8865\U53c8\U9632\U764c \U8ba9\U8702\U871c\U6548\U679c\U7ffb\U500d\U768415\U79cd\U5403\U6cd5";
        },
                {
            abstractInfo = "\U5403\U665a\U996d\U4e5f\U662f\U9700\U8981\U6ce8\U610f\U7684\U54df";
            downloadUrl = "http://183.230.40.64:5090/filemanage/firmwareDownload/b2a9ed2090598465c274eb6cf816150e/j2";
            id = 20;
            infoLocation = 1;
            redirectUrl = "http://183.230.40.64/portal/adsmanager/viewAd?id=20";
            title = "\U4e09\U79cd\U665a\U9910\U5929\U5929\U5403\U7b49\U4e8e\U201c\U81ea\U6740\U201d";
        },
                {
            abstractInfo = "\U5f88\U591a\U4eba\U90fd\U4f1a\U6709\U7761\U524d\U559d\U4e00\U676f\U725b\U5976\U7684\U4e60\U60ef\U3002\U4e00\U4e9b\U4eba\U62c5\U5fc3\U7761\U524d\U8fdb\U98df\U4f1a\U5e26\U6765\U70ed\U91cf\Uff0c\U4ee4\U8eab\U4f53\U53d1\U80d6\U3002\U4e8e\U662f\U5f00\U59cb\U731c\U60f3\Uff0c\U7761\U524d\U559d\U725b\U5976\U662f\U5426\U4f1a\U4ee4\U4eba\U957f\U80d6\U3002\U5176\U5b9e\Uff0c\U7761\U524d\U559d\U725b\U5976\Uff0c\U4e0d\U4ec5\U4e0d\U4f1a\U4ee4\U4eba\U957f\U80d6\Uff0c\U8fd8\U5927\U6709\U76ca\U5904\U3002";
            downloadUrl = "http://183.230.40.64:5090/filemanage/firmwareDownload/27e074dc9ac2df0d221298f574491f82/j3";
            id = 21;
            infoLocation = 1;
            redirectUrl = "http://183.230.40.64/portal/adsmanager/viewAd?id=21";
            title = "\U7761\U524d\U559d\U725b\U5976\U597d\U5904 \U7761\U524d\U559d\U725b\U5976\U4f1a\U957f\U80d6\U5417";
        }
    );
    version = 16;
}
2.Banner修正
Mat項目情報:downloadUrl:画像を表示する;redirectUrl:ジャンプアドレス;タイトル
{
    abstractInfo = "...";
    downloadUrl = "http://183.230.40.61/filemanage/firmwareDownload/e3c6b2c4ecdcb2938a5a4308deb42c6f/j1";
    id = 19;
    infoLocation = 1;
    redirectUrl = "http://183.230.40.62/portal/adsmanager/viewAd?id=19";
    title = "...";
}
CY項目情報:
{
        "extra_info" =         {
        };
        image = "http://img.chunyu.mobi/media/images/2015/04/13/f729352f294b_w640_h210_.jpg";
        "share_key" = "top_banner,413";
        title = "Mall\Uff0d\U5b9d\U5b9d\U6e05\U6d01\U4ea7\U54c1";
        type = vltr;
        url = "http://www.chunyuyisheng.com/mall/?category=bb_clean";
        version = "5.0.0";
}
変換コード:
- (NSMutableDictionary*) convertMatToChunyuWithDict: (NSMutableDictionary*) item {
    NSMutableDictionary* cyItem = [[NSMutableDictionary alloc] init];
    [cyItem setObject:[[NSDictionary alloc] init] forKey:@"extra_info"];
    [cyItem setObject:item[@"downloadUrl"] forKey:@"image"];
    [cyItem setObject:@"top_banner,1" forKey:@"share_key"];
    [cyItem setObject:item[@"title"] forKey:@"title"];
    [cyItem setObject:@"vltr" forKey:@"type"];
    [cyItem setObject:item[@"redirectUrl"] forKey:@"url"];
    [cyItem setObject:@"1.0.0" forKey:@"version"];

    return cyItem;
}
IOS - 首页横幅修改_第1张图片