美文网首页
表格 plist

表格 plist

作者: J_2009 | 来源:发表于2018-09-16 20:04 被阅读0次

    #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

          本文链接:https://www.haomeiwen.com/subject/wmvfnftx.html