一,效果图。

二,工程图。

三,代码。

RootViewController.h

#import <UIKit/UIKit.h>

@interface RootViewController : UIViewController
<UITableViewDelegate,UITableViewDataSource>
{
UITableView * city;
NSDictionary * dic;
}
@property(nonatomic,strong) NSArray * keyArray;
@end

RootViewController.m

#import "RootViewController.h"

@interface RootViewController ()

@end

@implementation RootViewController
@synthesize keyArray; - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
} - (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view. //初始化界面
[self initBackgroundView]; }
#pragma -mark -functions
-(void)initBackgroundView
{
city = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, 320, 460-44) style:UITableViewStylePlain];
city.delegate = self;
city.dataSource = self;
[self.view addSubview:city]; dic = [[NSDictionary alloc] initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"citydict" ofType:@"plist"]];
self.keyArray = [dic.allKeys sortedArrayUsingDescriptors:[NSArray arrayWithObjects:[NSSortDescriptor sortDescriptorWithKey:nil ascending:YES], nil]];
}
#pragma -mark -UITableViewDelegate
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return dic.count;
} -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
NSArray * array = [dic objectForKey:[self.keyArray objectAtIndex:section]];
return array.count;
} -(NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
{
return [self.keyArray objectAtIndex:section];
} -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:@"ID"];
if(cell == nil){
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"ID"];
}
cell.textLabel.text = [[dic objectForKey:[self.keyArray objectAtIndex:indexPath.section]] objectAtIndex:indexPath.row];
return cell;
} -(NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView
{
return self.keyArray;
} -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
NSLog(@"---didSelectRowAtIndexPath--");
} - (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}

【代码笔记】iOS-城市plist的更多相关文章

  1. IOS开发笔记 IOS如何访问通讯录

    IOS开发笔记  IOS如何访问通讯录 其实我是反对这类的需求,你说你读我的隐私,我肯定不愿意的. 幸好ios6.0 以后给了个权限控制.当打开app的时候你可以选择拒绝. 实现方法: [plain] ...

  2. iOS中plist的创建,数据写入与读取

    iOS中plist的创建,数据写入与读取 Documents:应用将数据存储在Documents中,但基于NSuserDefaults的首选项设置除外Library:基于NSUserDefaults的 ...

  3. iOS:城市级联列表的使用

    1.介绍: 现在越来越多的项目都用到了地址,尤其是电商O2O的购物平台,我之前做的教育产品和电商产品都用到了,而实现地址的设置用到的技术就是城市级联列表,即普遍的做法就是自定义选择器控件UIPicke ...

  4. 【hadoop代码笔记】Mapreduce shuffle过程之Map输出过程

    一.概要描述 shuffle是MapReduce的一个核心过程,因此没有在前面的MapReduce作业提交的过程中描述,而是单独拿出来比较详细的描述. 根据官方的流程图示如下: 本篇文章中只是想尝试从 ...

  5. 【hadoop代码笔记】hadoop作业提交之汇总

    一.概述 在本篇博文中,试图通过代码了解hadoop job执行的整个流程.即用户提交的mapreduce的jar文件.输入提交到hadoop的集群,并在集群中运行.重点在代码的角度描述整个流程,有些 ...

  6. 【Hadoop代码笔记】目录

    整理09年时候做的Hadoop的代码笔记. 开始. [Hadoop代码笔记]Hadoop作业提交之客户端作业提交 [Hadoop代码笔记]通过JobClient对Jobtracker的调用看详细了解H ...

  7. 笔记-iOS 视图控制器转场详解(上)

    这是一篇长文,详细讲解了视图控制器转场的方方面面,配有详细的示意图和代码,为了使得文章在微信公众号中易于阅读,seedante 辛苦将大量长篇代码用截图的方式呈现,另外作者也在 Github 上附上了 ...

  8. 蜗牛爱课- iOS中plist的创建,数据写入与读取

    iOS中plist的创建,数据写入与读取功能创建一个test.plist文件-(void)triggerStorage{    NSArray *paths=NSSearchPathForDirect ...

  9. <Python Text Processing with NLTK 2.0 Cookbook>代码笔记

    如下是<Python Text Processing with NLTK 2.0 Cookbook>一书部分章节的代码笔记. Tokenizing text into sentences ...

  10. delphi ios info.plist

    delphi ios info.plist delphi修改info.plist.TemplateiOS.xml文件,然后自动生成project1.info.plist http://docwiki. ...

随机推荐

  1. SQL 语句的TOP,Distinct语句

    --Top获取前几条数据,一般都与Order By连用 SELECT TOP 3 * FROM dbo.MyStudent --查询Student表中前3条所有的数据 SELECT TOP 3 S_N ...

  2. LeetCode - 54. Spiral Matrix

    54. Spiral Matrix Problem's Link ------------------------------------------------------------------- ...

  3. MVC4在IIS6上部署遇到的问题

    最近的一个项目结束了,花的时间一个月左右吧..... 开发环境 win7+VS2012+MVC4(.net 4.0)+SQL SERVER 2008 部署环境 windows server 2003 ...

  4. 微信--获取jsapi_ticket 然后在计算出signature

    最近做微信公众号,记录一下,仅供参看. 关于jsapi_ticket微信公众号有相关说明: 生成签名之前必须先了解一下jsapi_ticket,jsapi_ticket是公众号用于调用微信JS接口的临 ...

  5. js 模板引擎 为什么选择 dot

    我的上篇博文详细介绍了jquery tmpl,因为我想在我的项目里引入JS模版,所以就研究了一下,有人告诉我这个引擎的速度很慢,于是我又去搜集了一下资料,结果发现jquery tmpl是最慢的,于是乎 ...

  6. 【原创】asp.net导出word 检索 COM 类工厂中 CLSID 为 {000209FF-0000-0000-C000-000000000046} 的组件失败,原因是出现以下错误: 8000401a

    我的服务器:windows server 2008(64位)+microsoft office 2007 企业版 业务:网站导出应聘word简历. 出现以下错误: 检索 COM 类工厂中 CLSID ...

  7. UITextView 文本垂直居中

    var center=textView.Bounds.Size.Height - textView.ContentSize.Height; center = center < ? : cente ...

  8. 从NavigationController 下的UITableView中移除 header

    this.AutomaticallyAdjustsScrollViewInsets = false; 解析:AutomaticallyAdjustsScrollViewInsets为系统自动为适应na ...

  9. 不可或缺 Windows Native (20) - C++: 友元函数, 友元类

    [源码下载] 不可或缺 Windows Native (20) - C++: 友元函数, 友元类 作者:webabcd 介绍不可或缺 Windows Native 之 C++ 友元函数 友元类 示例演 ...

  10. GJM : Unity3D - NetWork - Hight Level API ( HLAPI) [转载]

    介绍在本系列教程中,我们将使用的网络高级API(HLAPI)来构建一个小型的多人网络案例.即使我们的例子很简单,但也会涵盖以下关键概念,这应该可以帮助大家使用HLAPI构建大型游戏项目. 在第一部分, ...