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