Demo entry 5865300

12313

   

Submitted by anonymous on Aug 15, 2016 at 08:54
Language: Objective-C++. Code size: 6.6 kB.

//
//  CityListViewController.m
//  MobileProject
//
//  Created by mac on 16/7/21.
//  Copyright © 2016年 wujunyang. All rights reserved.
//

#import "CityListViewController.h"
#import "MerchantsListVC.h"
#import "MBProgressHUD.h"
@interface CityListViewController ()<UITableViewDataSource,UITableViewDelegate>
{
    NSMutableArray *allDataArray;
    NSMutableArray *allProvenceList;
    UITableView *mainTableView;
}
@end

@implementation CityListViewController

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    
    if (self.levelNum == 0) {
        [self netWorkGetCityList:^(BOOL isSucess, NSMutableArray *cityData, NSString *error) {
            
            allDataArray = cityData;
            for (NSDictionary *dic in cityData) {
                NSString *p = dic[@"p"];
                [allProvenceList addObject:p];
            }
            [mainTableView reloadData];
            
        }];
    }else if (self.levelNum == 1)
    {
        NSDictionary *dic = self.dataDic;
        allDataArray = dic[@"c"];
        for (NSDictionary *dic in allDataArray) {
            NSDictionary *n = dic[@"n"];
            [allProvenceList addObject:n];
        }
        [mainTableView reloadData];
        
    }else if (self.levelNum == 2)
    {
        NSDictionary *dic = self.dataDic;
        allDataArray = dic[@"a"];
        for (NSDictionary *dic in allDataArray) {
            NSDictionary *s = dic[@"s"];
            [allProvenceList addObject:s];
        }
        [mainTableView reloadData];
        
    }

}


- (void)viewDidLoad {
    [super viewDidLoad];

    allDataArray = [NSMutableArray array];
    allProvenceList = [NSMutableArray array];
    
    self.view.backgroundColor = [UIColor whiteColor];
    [self initTableView];
}
#pragma mark - 创建tableview  UITableViewDataSource,UITableViewDelegate
- (void)initTableView
{
   
    mainTableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, Main_Screen_Width, Main_Screen_Height-64) style:UITableViewStyleGrouped];
    mainTableView.backgroundColor = [UIColor whiteColor];
    mainTableView.tableHeaderView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, Main_Screen_Width, 1)];
    mainTableView.delegate = self;
    mainTableView.dataSource = self;
    UIView *footView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, Main_Screen_Width, 64)];
    footView.backgroundColor = [UIColor whiteColor];
    mainTableView.tableFooterView = footView;
    [self.view addSubview:mainTableView];
    
    
    
}
#pragma mark - tableview的组数
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}

#pragma mark- tableview的每一组行数
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return allProvenceList.count;
}

#pragma mark - tableview的单元格风格
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *identifier = @"myCell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
    if (!cell) {
        cell  = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];
    }
    cell.backgroundColor = [UIColor whiteColor];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    cell.textLabel.text = allProvenceList[indexPath.row];
    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    return cell;
    
}

#pragma mark - tableview的每一行的高度
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 50;
    
}

#pragma mark - tableview的每一组的头视图高度
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return 0;
}
//#pragma mark - tableview的每一组的尾部视图高度
//- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
//{
//    return 10;
//}
#pragma mark - 点击tableview方法
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    
   
    NSString *currenAddress =allProvenceList[indexPath.row];
    NSMutableArray *array = self.addressArray;
    [array addObject:currenAddress];

    NSDictionary *citydic = allDataArray[indexPath.row];
    CityListViewController *city = [[CityListViewController alloc]init];
    city.levelNum = self.levelNum+1;
    city.dataDic = citydic;
    city.address = [NSString stringWithFormat:@"%@%@",self.address,allProvenceList[indexPath.row]];
    city.addressArray = array;
    if ([citydic allValues].count==1) {
           NSLog(@"层级:%@",self.navigationController.viewControllers);
           NSLog(@"地区:%@",city.address);
           
           NSNotification *notif = [NSNotification notificationWithName:@"myAddress" object:self userInfo:@{@"address":city.address,@"addressArr":array}];
           [[NSNotificationCenter defaultCenter]postNotification:notif];
           
           MerchantsListVC *mer = self.navigationController.viewControllers[1];
           [self.navigationController popToViewController:mer animated:YES];
    }else{
           [self.navigationController pushViewController:city animated:YES];

    }
    
    


    
   
}


- (void)netWorkGetCityList:(void(^)(BOOL isSucess,NSMutableArray *cityData,NSString *error))block
{
    [MBProgressHUD showHUDAddedTo:self.view animated:YES];
    NSString *url = @"Api/Index/getJSONAdress";
    [DataProvider PostData:url param:nil finish:^(NSData *data, NSDictionary *obj, NSError *error) {
        [MBProgressHUD hideHUDForView:self.view animated:YES];

        if ([obj[@"status"] isEqualToString:@"1"]) {
            
            NSDictionary *dic = obj[@"data"];
            NSArray *list = dic[@"citylist"];
            NSMutableArray *array = [NSMutableArray arrayWithArray:list];
            block(YES,array,nil);
            
        }else{
            block(NO,nil,obj[@"msg"]);
        }

    }];
}




- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end

This snippet took 0.02 seconds to highlight.

Back to the Entry List or Home.

Delete this entry (admin only).