一,效果图。

二,工程图。

三,代码。

ChooseCityViewController.h

#import <UIKit/UIKit.h>

@interface ChooseCityViewController : UIViewController
<UITableViewDelegate,UITableViewDataSource>
{
NSMutableArray * dataArray;
UITableView * mTableView;
} @end

ChooseCityViewController.m

#import "ChooseCityViewController.h"
#import "DetailViewController.h" @interface ChooseCityViewController () @end @implementation ChooseCityViewController - (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. //读取plist文件
[self readPlistFile];
//初始化tableView
[self initTableView]; }
#pragma -mark -functions -(void)readPlistFile
{
dataArray = [[NSMutableArray alloc] initWithCapacity:0];
NSString * path = [[NSBundle mainBundle] pathForResource:@"city" ofType:@"plist"]; NSDictionary * dict = [[NSDictionary alloc] initWithContentsOfFile:path];
NSEnumerator * enumerator = [dict keyEnumerator];
NSString * key;
while (key = [enumerator nextObject]) {
NSDictionary * t = [dict objectForKey:key]; [dataArray addObject:t];
}
NSLog(@"%@",dataArray);
} -(void)initTableView
{
mTableView = [[UITableView alloc] initWithFrame:self.view.bounds style:UITableViewStylePlain];
mTableView.delegate = self;
mTableView.dataSource = self;
mTableView.autoresizingMask = UIViewAutoresizingFlexibleHeight;
[self.view addSubview:mTableView]; }
#pragma -UITableViewDelegate
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [dataArray count];
} -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString * ID = @"cellID";
UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:ID];
if (cell == nil)
{
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:ID];
}
NSDictionary *dict = [dataArray objectAtIndex:indexPath.row];
cell.textLabel.text = [dict objectForKey:@"city_name"];
return cell;
} -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
NSDictionary * dict = [dataArray objectAtIndex:indexPath.row];
//把所选择的城市保存到本地
[[NSUserDefaults standardUserDefaults] setObject:[dict objectForKey:@"city_id"] forKey:@"city_id"];
[[NSUserDefaults standardUserDefaults] setObject:[dict objectForKey:@"city_name"] forKey:@"city_name"]; //跳转到另一个有tabbar的页面
DetailViewController *detail=[[DetailViewController alloc]init];
[self.navigationController pushViewController:detail animated:NO];
} - (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
 
 

【代码笔记】iOS-先选择城市,然后,跳转Tabbar的更多相关文章

  1. 【代码笔记】iOS-点击城市中的tableView跳转到旅游景点的tableView,下面会有“显示”更多。

    一,效果图. 二,工程图. 三,代码. RootViewController.h #import <UIKit/UIKit.h> @interface RootViewController ...

  2. 【代码笔记】iOS-页面之间的跳转效果

    一,工程图. 二,代码. RootViewController.m -(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { ...

  3. 【代码笔记】iOS-plist获得城市列表

    一,工程图. 二,代码. - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the ...

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

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

  5. h5手机端下拉选择城市

    <!doctype html><html>    <head>            <meta http-equiv="Content-Type& ...

  6. jquery实现输入框聚焦,键盘上下键选择城市

    在最近有个项目中 需要实现当文本框聚焦的时候,可以键盘上下键选择内容,按enter键的时候,把内容传到输入框中,如图所示: 实现代码如下: /** *输入框聚焦,键盘上下键选择城市 */ ;(func ...

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

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

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

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

  9. IOS 如何选择delegate、notification、KVO?

    IOS 如何选择delegate.notification.KVO? 博客分类: IOS   前面分别讲了delegate.notification和KVO的实现原理,以及实际使用步骤,我们心中不禁有 ...

随机推荐

  1. js的作业题

    <script type="text/javascript"> //var a=3; //switch(a) // { // case 1: // alert(&quo ...

  2. CSS3制作心形头像

    1.功能需求: 最近有一个基于微信开发的Mobile Web项目,是一个活动页面.功能需求:用户使用微信扫描二维码,然后授权使用微信登录,然后读取用户的昵称和头像,然后显示在一个饼图上面.头像需要有一 ...

  3. 移动前端开发-单页应用(spa)模型

    一门新的技术诞生总会引来一番争议,单页Web应用程序也不例外,其最大的优势在于用户体验,对于内容的改动不需要加载整个页面:对服务器压力很小,消耗更少的带宽,与面向服务的架构更好地结合.使用HTML+C ...

  4. (八)WebGIS中栅格图层的设计

    文章版权由作者李晓晖和博客园共有,若转载请于明显处标明出处:http://www.cnblogs.com/naaoveGIS/. 1.    前言 我们在上一章里了解到WebGIS中栅格图层的本质—— ...

  5. 将DataTable转换成CSV文件

    DataTable用于在.net项目中,用于缓存数据,DataTable表示内存中数据的一个表.CSV文件最早用在简单的数据库里,由于其格式简单,并具备很强的开放性,所以起初被扫图家用作自己图集的标记 ...

  6. Xamarin.Android之Spinner的简单探讨

    一.前言 今天用了一下Spinner这个控件,主要是结合官网的例子来用的,不过官网的是把数据写在Strings.xml中的, 某种程度上,不是很符合我们需要的,比较多的应该都是从数据库读出来,绑定上去 ...

  7. HtmlHelper拓展实现CheckBoxList

    经过一番折腾(主要是SelectList这个类操作有些繁琐)实现了CheckBoxList,过程RadioList基本一样 拓展方法 public static MvcHtmlString Check ...

  8. HttpWebRequest的GetResponse或GetRequestStream偶尔超时 + 总结各种超时死掉的可能和相应的解决办法

    [问题] 用C#模拟网页登陆,其中去请求几个页面,会发起对应的http的请求request,其中keepAlive设置为true,提交请求后,然后会有对应的response: resp = (Http ...

  9. 微信JSApi支付~订单号和微信交易号

    返回目录 谈谈transactionId和out_trade_no 前一篇微信JSApi支付~坑和如何填坑文章反映不错,所以又写了个后篇,呵呵. 每个第三方在线支付系统中都会有至少两类订单号,其一为支 ...

  10. How do I see all foreign keys to a table or column?

    down voteaccepted For a Table: SELECT TABLE_NAME,COLUMN_NAME,CONSTRAINT_NAME, REFERENCED_TABLE_NAME, ...