【代码笔记】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的实现原理,以及实际使用步骤,我们心中不禁有 ...
随机推荐
- 使用Genymotion调试出现错误INSTALL_FAILED_CPU_ABI_INCOMPATIBLE解决办法
需要下载Genymotion-ARM-Translation_v1.1.zip ARM插件包 用于安装ARM架构的程序,将下载好的zip包用鼠标拖到虚拟机窗口中,出现确认对跨框点OK就行.然后重启你 ...
- javascript中函数声明和函数表达式浅析
记得在面试腾讯实习生的时候,面试官问了我这样一道问题. //下述两种声明方式有什么不同 function foo(){}; var bar = function foo(){}; 当初只知道两种声明方 ...
- Visual Studio常用小技巧一:代码段+快捷键+插件=效率
用了visual studio 5年多,也该给自己做下备忘录了.每次进新的组换新的电脑,安装自己熟悉的环境又得重新配置,不做些备忘老会忘记一些东西.工具用的好,效率自然翻倍. 1,代码段 在Visua ...
- 修改USB固件库的Customer_HID例程
我用的是神州三号开发板子,板子的USB模块原理图为: 配置端口G的11号引脚为usb的使能引脚,按理来说应该是开漏输出的(看了很多的修改代码都是这个模式),不过就是不能使能usb,只能配置成推挽的才行 ...
- geotrellis使用(二十一)自动导入数据
目录 前言 整体介绍 前台界面 后台控制 总结 一.前言 之前Geotrellis数据导入集群采用的是命令行的方式,即通过命令行提交spark任务来ingest数据,待数据导入完毕再启动 ...
- Visual Studio Code 智能提示文件
Visual Studio Code 开发前端和node智能提示 visual studio code 是一个很好的编辑器,可以用来编写前端代码和nodejs. 我很喜欢使用VSC,现在流行框架对VS ...
- linux dd命令详解
Linux-dd命令详解 dd 是 Linux/UNIX 下的一个非常有用的命令,作用是用指定大小的块拷贝一个文件,并在拷贝的同时进行指定的转换. 名称: dd 使用权限: 所有使用者dd 这个指令在 ...
- 解决ajax跨域请求 (总结)
ajax跨域请求,目前已用几种方法实现: 1)用原生js的xhr对象实现. var url="http://freegeoip.net/json/" ...
- Machine Learning
Recently, I am studying Maching Learning which is our course. My English is not good but this course ...
- servlet中用注解的方式读取web.xml中的配置信息
在学习servletContext的时候,我们知道了可以在web.xml中通过<context-param>标签来定义全局的属性(所有servlet都能读取的信息),并在servlet中通 ...