表格 plist

#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

你可能感兴趣的:(表格 plist)