iOS -读取plist文件
2015-07-31 08:29
501 查看
// UI-城市列表
//
// Created by jzq_mac on 15/7/30.
// Copyright (c) 2015年 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 ----------------------获得plist里面的数据----------------------
- (void)loadData{
NSString *path = [[NSBundle mainBundle] pathForResource:@"citys.plist" ofType:nil];
allCitys = [NSArray arrayWithContentsOfFile:path];
NSLog(@"%@", allCitys);
}
#pragma ----------------------初始化TableView----------------------
- (void)creatTableView
{
myTableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 20, 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的唯一标识符
// TableView查找有没有叫cellID的cell(满一屏的情况)
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID];
//
如果没有查找到就初始化cell
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];
// 模态切换ViewController;用于临时切换到另一个ViewController,把需要显示的ViewController放在最上面
presentedViewController
// 当不再需要刚才放到最上面的ViewController的时候
让他消失dismissViewControllerAnimated
detail.modalTransitionStyle = UIModalTransitionStylePartialCurl;
[self presentViewController:detail animated:YES completion:nil];
}
//
// Created by jzq_mac on 15/7/30.
// Copyright (c) 2015年 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 ----------------------获得plist里面的数据----------------------
- (void)loadData{
NSString *path = [[NSBundle mainBundle] pathForResource:@"citys.plist" ofType:nil];
allCitys = [NSArray arrayWithContentsOfFile:path];
NSLog(@"%@", allCitys);
}
#pragma ----------------------初始化TableView----------------------
- (void)creatTableView
{
myTableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 20, 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的唯一标识符
// TableView查找有没有叫cellID的cell(满一屏的情况)
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID];
//
如果没有查找到就初始化cell
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];
// 模态切换ViewController;用于临时切换到另一个ViewController,把需要显示的ViewController放在最上面
presentedViewController
// 当不再需要刚才放到最上面的ViewController的时候
让他消失dismissViewControllerAnimated
detail.modalTransitionStyle = UIModalTransitionStylePartialCurl;
[self presentViewController:detail animated:YES completion:nil];
}
相关文章推荐
- iOS8新特性扩展(Extension)应用之二——分享插件
- 类似ios的picker的风格地址选择控件
- ios开发之发送UDP广播并接收数据
- 获取当前IOS设备的CPU型号,CPU核数,GPU,GPU核数,屏幕分辨率,屏幕尺寸,PPI等信息
- IOS培训:19个必须知道的Visual Studio快捷键
- iOS将耳机音量调节到最大的方法
- IOS设计模式
- iOS开发中的测试框架
- iOS优化之路
- IOS的生命周期问题
- [转]iOS 中几种定时器 - 控制了时间,就控制了一切
- 对IOS新手开发有帮助的一些小代码
- iOS基础--数据解析(XML)
- iOS7 手势滑动返回 interactivePopGestureRecognizer
- IOS 创建含有category的静态库,selector not recognized的解决方案
- Mac和IOS下使用OpenCV
- iOS开发:StoryBoard 使用Block在两个界面之间传值
- 我在ios开发道路上的学习心得及阶段性收获
- IOS 图片上传处理 图片压缩 图片处理
- 基于Ios的简单点名器程序