表格 plist

2018-09-16  本文已影响0人  J_2009

#import "ProivceTableViewController.h"

#import "LBSViewController.h"

@interface ProivceTableViewController ()

{

    NSDictionary*_tableDataDic;

}

@end

@implementationProivceTableViewController

- (void)viewDidLoad {

    [super viewDidLoad];

    // Uncomment the following line to preserve selection between presentations.

    // self.clearsSelectionOnViewWillAppear = NO;

    // Uncomment the following line to display an Edit button in the navigation bar for this view controller.

    // self.navigationItem.rightBarButtonItem = self.editButtonItem;

    // 路径字符串

    NSString *filePath = [[NSBundle mainBundle]pathForResource:@"Province" ofType:@"plist"];

    _tableDataDic = [[NSDictionary alloc]initWithContentsOfFile:filePath];

    [self.tableView reloadData];

}

- (void)didReceiveMemoryWarning {

    [super didReceiveMemoryWarning];

    // Dispose of any resources that can be recreated.

}

-(NSInteger)numberOfSectionsInTableView:(UITableView*)tableView{

    return _tableDataDic.count;

}

- (NSInteger)tableView:(UITableView*)tableView numberOfRowsInSection:(NSInteger)section{

    NSArray*provinceArr=_tableDataDic[_tableDataDic.allKeys[section]];

    returnprovinceArr.count;

}

- (UITableViewCell*)tableView:(UITableView*)tableView cellForRowAtIndexPath:(NSIndexPath*)indexPath{

    staticNSString*sta=@"sta";

    UITableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:sta];

    if(!cell) {

        cell=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:sta];

    }

    NSArray*provinceArr =_tableDataDic[_tableDataDic.allKeys[indexPath.section]];

    NSDictionary*provinceDic = provinceArr[indexPath.row];

    cell.textLabel.text=provinceDic[@"provincial capital"];

    cell.detailTextLabel.text=provinceDic[@"city"];

    returncell;

}

-(NSString*)tableView:(UITableView*)tableView titleForHeaderInSection:(NSInteger)section{

    return_tableDataDic.allKeys[section];

}

-(void)tableView:(UITableView*)tableView didSelectRowAtIndexPath:(NSIndexPath*)indexPath{

    NSArray*provinceArr =_tableDataDic[_tableDataDic.allKeys[indexPath.section]];

    NSDictionary*provinceDic = provinceArr[indexPath.row];

    LBSViewController *lbs = [[LBSViewController alloc]init];

    lbs.locationString= [NSStringstringWithFormat:@"%@@",provinceDic[@"provincial capital"],provinceDic[@"city"]];

    [self.navigationController pushViewController:lbs animated:YES];

}

@end

上一篇 下一篇

猜你喜欢

热点阅读