本文实例为大家分享了ios选择城市后跳转tabbar的具体实现代码,供大家参考,具体内容如下
一、效果图
二、工程图
三、代码
choosecityviewcontroller.h
?
1
2
3
4
5
6
7
8
9
10
|
#import <uikit/uikit.h>
@interface choosecityviewcontroller : uiviewcontroller
<uitableviewdelegate,uitableviewdatasource>
{
nsmutablearray * dataarray;
uitableview * mtableview;
}
@end
|
choosecityviewcontroller.m
?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
|
#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.
}
|
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持快网idc。
相关文章
猜你喜欢
- 个人网站搭建:如何挑选具有弹性扩展能力的服务器? 2025-06-10
- 个人服务器网站搭建:如何选择适合自己的建站程序或框架? 2025-06-10
- 64M VPS建站:能否支持高流量网站运行? 2025-06-10
- 64M VPS建站:怎样选择合适的域名和SSL证书? 2025-06-10
- 64M VPS建站:怎样优化以提高网站加载速度? 2025-06-10
TA的动态
- 2025-07-10 怎样使用阿里云的安全工具进行服务器漏洞扫描和修复?
- 2025-07-10 怎样使用命令行工具优化Linux云服务器的Ping性能?
- 2025-07-10 怎样使用Xshell连接华为云服务器,实现高效远程管理?
- 2025-07-10 怎样利用云服务器D盘搭建稳定、高效的网站托管环境?
- 2025-07-10 怎样使用阿里云的安全组功能来增强服务器防火墙的安全性?
快网idc优惠网
QQ交流群
您的支持,是我们最大的动力!
热门文章
-
2025-06-04 27
-
2025-05-29 48
-
2025-06-04 93
-
2025-05-29 103
-
2025-05-29 30
热门评论