IOS-Read plist files

Source: Internet
Author: User

ui- City List

//

Created by Jzq_mac on 15/7/30.

Copyright (c) year Jzq_mac. All rights reserved.

//


#import "ViewController.h"

#import "DetailViewController.h"

@interface Viewcontroller () <UITableViewDataSource,UITableViewDelegate>

{

Nsarray *allcitys;

UITableView *mytableview;

}

@end


@implementation Viewcontroller


-(void) Viewdidload {

[Super Viewdidload];

[Self loaddata];

[Self creattableview];

}




#pragma---------------------- get The data inside the plist----------------------


-(void) loaddata{

NSString *path = [[NSBundle mainbundle] pathforresource:@ "citys.plist" oftype:nil];

Allcitys = [Nsarray Arraywithcontentsoffile:path];

NSLog (@ "%@", Allcitys);

}



#pragma---------------------- Initialize the TableView----------------------


-(void) Creattableview

{

Mytableview = [[UITableView alloc]initwithframe:cgrectmake (0, Cgrectgetwidth (self.view.frame), Cgrectgetheight ( Self.view.frame) -20) Style:uitableviewstyleplain];

Mytableview.delegate = self;

Mytableview.datasource = self;

[Self.view Addsubview:mytableview];

}




#pragma----------------------uitableviewdelegate---------------------

-(Nsinteger) TableView: (UITableView *) TableView numberofrowsinsection: (nsinteger) Section

{

return allcitys.count;

}



#pragma----------------------Uitableviewdatasource---------------------

-(UITableViewCell *) TableView: (UITableView *) TableView Cellforrowatindexpath: (Nsindexpath *) Indexpath

{

NSString *cellid = @ "Citycell";//cell 's unique identifier

TableView Find the cell with the name Cellid(full screen case)

UITableViewCell *cell = [TableView dequeuereusablecellwithidentifier:cellid];

// Initialize cell If no search is found

if (!cell) {

cell = [[UITableViewCell alloc]initwithstyle:uitableviewcellstyledefault reuseidentifier:cellid];

}

Cell.textLabel.text = allcitys[indexpath.row][@ "state"];

return cell;

}




-(void) TableView: (UITableView *) TableView Didselectrowatindexpath: (Nsindexpath *) Indexpath

{

Detailviewcontroller *detail = [[Detailviewcontroller alloc]init];

modal switching viewcontroller; for temporarily switching to another Viewcontroller, place the viewcontroller thatneed to be displayed on top Presentedviewcontroller

let him disappear when it 's no longer necessary to put it on top of the Viewcontroller dismissviewcontrolleranimated

Detail.modaltransitionstyle = Uimodaltransitionstylepartialcurl;

[Self presentviewcontroller:detail animated:yes completion:nil];

}



Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

IOS-Read plist files

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.