【代码笔记】iOS-先选择城市,然后,跳转Tabbar
一,效果图。


二,工程图。

三,代码。
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的更多相关文章
- 【代码笔记】iOS-点击城市中的tableView跳转到旅游景点的tableView,下面会有“显示”更多。
一,效果图. 二,工程图. 三,代码. RootViewController.h #import <UIKit/UIKit.h> @interface RootViewController ...
- 【代码笔记】iOS-页面之间的跳转效果
一,工程图. 二,代码. RootViewController.m -(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { ...
- 【代码笔记】iOS-plist获得城市列表
一,工程图. 二,代码. - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the ...
- IOS开发笔记 IOS如何访问通讯录
IOS开发笔记 IOS如何访问通讯录 其实我是反对这类的需求,你说你读我的隐私,我肯定不愿意的. 幸好ios6.0 以后给了个权限控制.当打开app的时候你可以选择拒绝. 实现方法: [plain] ...
- h5手机端下拉选择城市
<!doctype html><html> <head> <meta http-equiv="Content-Type& ...
- jquery实现输入框聚焦,键盘上下键选择城市
在最近有个项目中 需要实现当文本框聚焦的时候,可以键盘上下键选择内容,按enter键的时候,把内容传到输入框中,如图所示: 实现代码如下: /** *输入框聚焦,键盘上下键选择城市 */ ;(func ...
- 【hadoop代码笔记】hadoop作业提交之汇总
一.概述 在本篇博文中,试图通过代码了解hadoop job执行的整个流程.即用户提交的mapreduce的jar文件.输入提交到hadoop的集群,并在集群中运行.重点在代码的角度描述整个流程,有些 ...
- 笔记-iOS 视图控制器转场详解(上)
这是一篇长文,详细讲解了视图控制器转场的方方面面,配有详细的示意图和代码,为了使得文章在微信公众号中易于阅读,seedante 辛苦将大量长篇代码用截图的方式呈现,另外作者也在 Github 上附上了 ...
- IOS 如何选择delegate、notification、KVO?
IOS 如何选择delegate.notification.KVO? 博客分类: IOS 前面分别讲了delegate.notification和KVO的实现原理,以及实际使用步骤,我们心中不禁有 ...
随机推荐
- JavaScript中的日期处理注意事项
在业务逻辑比较多的系统里面,一般都会涉及到日期的处理.包括选择起始日期和结束日期,结束日期要大于起始日期,日期的显示和输入等. 输入这一块基本都是使用jQuery datetimepicker,后来系 ...
- 【记录】AutoMapper Project To not support ResolveUsing
示例代码: public List<OrderLineDTO> GetLinesForOrder(int orderId) { Mapper.CreateMap<OrderLine, ...
- xcode6 使用MJRefresh,Too many arguments to function call, expected 0, have *
转载自: http://blog.csdn.net/wsjshx/article/details/40743291 将XCode升级到6后,报Too many arguments to functi ...
- 异步Promise实现
简介 异步回调的书写往往打乱了正常流的书写方式,在ECMAScript 6中实现了标准的Promise API,旨在 解决控制回调流程的问题. 简单的实现了Promise API: (function ...
- SQL SERVER四舍五入你除了用ROUND还有其他方法吗?
引言 今天和测试沟通一个百分比计算方式时遇到一个问题, 我在存储过程里用到了强转CAST(32.678 AS DECIMAL(5,1)) 我认为该方式只会保留一位小数,我给测试的回复是我并没有用到四 ...
- javascript判断元素存在和判断元素存在于实时的dom中的方法
今天(周六)下午我在公司加班时不知道要干什么,就打开公司的一个wordpress项目网站,想看下之前自己做的一个网页是否有问题. 打开网站首页,我习惯性的打开了chrome的调试工具,然后鼠标开始滚动 ...
- 数据库join方式分析
前言 不管是博客园还是CSDN,看到很多朋友对数据库的理解.认识还是没有突破一个瓶颈 ,而这个瓶颈往往只是一层窗纸,越过了你将看到一个新世界. 04.05年做项目的时候,用SQL Serv ...
- jackson error 含义log
1. 反序列化失败,类型不匹配 Caused by: com.fasterxml.jackson.databind.JsonMappingException: Can not deserial ize ...
- Dapper ORM VS SqlSugar ORM的 8场对决
CUP和.NET SQL版本不同也会存在少许差距,但不会有质变,下面的测试结果仅供参考 比赛规则 1.统一使用Realse版本的最新 DLL,Realse模式启用程序 2.为了平衡CPU和数据库空闲情 ...
- 程序集与反射技术(C#)
首先我们来看程序集,程序集是代码进行编译是的一个逻辑单元,把相关的代码和类型进行组合,然后生成PE文件(例如可执行文件.exe和类库文件.dll).由于程序集在编译后并不一定会生成单个文件,而可能会生 ...