服务器之家:专注于VPS、云服务器配置技术及软件下载分享
分类导航

PHP教程|ASP.NET教程|Java教程|ASP教程|编程技术|正则表达式|C/C++|IOS|C#|Swift|Android|VB|R语言|JavaScript|易语言|vb.net|

服务器之家 - 编程语言 - IOS - IOS开发之tableView点击行跳转并带有“显示”更多功能

IOS开发之tableView点击行跳转并带有“显示”更多功能

2021-01-09 17:33Livia.Chen IOS

这篇文章给大家介绍通过点击城市中的tableView跳转到旅游景点的tableView,下面会有“显示”更多的功能,代码简单易懂,对ios点击tableview跳转相关知识感兴趣的朋友一起学习吧

首先给大家展示下效果图,觉得还满意的话,请继续学习代码实现过程。

IOS开发之tableView点击行跳转并带有“显示”更多功能

一,工程图。

IOS开发之tableView点击行跳转并带有“显示”更多功能

二,代码。

rootviewcontroller.h

?
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
#import <uikit/uikit.h>
@interface rootviewcontroller : uiviewcontroller
<uitableviewdelegate,uitableviewdatasource>
{
uitableview * _tableview;
nsmutablearray * provincearray;
}
@end
 
rootviewcontroller.m
 
#import "rootviewcontroller.h"
//详细页面
#import "detailviewcontroller.h"
@interface rootviewcontroller ()
@end
@implementation rootviewcontroller
- (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.
provincearray = [[nsmutablearray alloc] initwithobjects:@"北京", @"上海", @"云南",@"四川",@"海南", @"江苏", @"香港", @"澳门", @"西藏", nil];
_tableview = [[uitableview alloc] initwithframe:cgrectmake(0, 0, 320, 380) style:uitableviewstylegrouped];
_tableview.delegate = self;
_tableview.datasource = self;
[self.view addsubview:_tableview];
}
#pragma -mark -uitableviewdelegate
- (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 = [provincearray objectatindex:indexpath.row];
cell.accessorytype = uitableviewcellaccessorydisclosureindicator;
return cell;
}
- (nsinteger)tableview:(uitableview *)tableview numberofrowsinsection:(nsinteger)section {
return 9;
}
- (cgfloat)tableview:(uitableview *)tableview heightforrowatindexpath:(nsindexpath *)indexpath {
return 60;
}
//点击进入下一页
- (void)tableview:(uitableview *)tableview didselectrowatindexpath:(nsindexpath *)indexpath {
detailviewcontroller* svc = [[detailviewcontroller alloc] init];
svc.title = [nsstring stringwithformat:@"%@",[provincearray objectatindex:indexpath.row]];
[self.navigationcontroller pushviewcontroller:svc animated:no];
}
- (void)didreceivememorywarning
{
[super didreceivememorywarning];
// dispose of any resources that can be recreated.
}
/*
#pragma mark - navigation
// in a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareforsegue:(uistoryboardsegue *)segue sender:(id)sender
{
// get the new view controller using [segue destinationviewcontroller].
// pass the selected object to the new view controller.
}
*/
@end

detailviewcontroller.h

?
1
2
3
4
5
6
7
8
9
10
11
12
13
#import <uikit/uikit.h>
@interface detailviewcontroller : uiviewcontroller
<uitableviewdelegate,uitableviewdatasource>
{
uitableview* _tableview;
nsarray* provincearr;
nsarray* cityarray;
nsstring* cityname;
nsmutablearray* ditailname;
nsstring* ditialplacename;
nsdictionary *dicforplist;
}
@end

detailviewcontroller.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
94
95
96
97
98
99
#import "detailviewcontroller.h"
static int rownumber;
@interface detailviewcontroller ()
@end
@implementation detailviewcontroller
- (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.
//传过来的城市名字
cityname = self.title;
//tableview显示行数
rownumber = 20;
//tableview
_tableview = [[uitableview alloc] initwithframe:cgrectmake(0, 0, 320, 460 ) style:uitableviewstylegrouped];
_tableview.delegate = self;
_tableview.datasource = self;
[self.view addsubview:_tableview];
nsmutablearray* citycomparearr = [[nsmutablearray alloc] init];
ditailname = [[nsmutablearray alloc] init];
//城市的plist文件
dicforplist = [nsdictionary dictionarywithcontentsoffile:[[nsbundle mainbundle] pathforresource:@"cityname" oftype:@"plist"]];
//北京所有数据
provincearr = [dicforplist objectforkey:cityname];
for (int j = 0; j < [provincearr count]; j++) {//遍历省的所有数据
cityarray = [provincearr objectatindex:j];//取出每一个小数组
for (int i = 0; i < [cityarray count]; i++) {//遍历小数组
nsstring* strstr = [cityarray objectatindex:i]; //得到小数组内容
if ([strstr isequaltostring:cityname] && j + 1 < [provincearr count]) {
citycomparearr = [provincearr objectatindex:j + 1];
if (![[cityarray objectatindex:i + 1] isequaltostring:[citycomparearr objectatindex:i + 1]]) {
[ditailname addobject:[cityarray objectatindex:i + 1]];
} else {
}
}
if ([strstr isequaltostring:cityname] && j + 1 == [provincearr count]){
nslog(@"last one?");
}
}
}
}
#pragma -mark -uitableviewdelegate
- (uitableviewcell *)tableview:(uitableview *)tableview cellforrowatindexpath:(nsindexpath *)indexpath {
uitableviewcell* cell = [tableview dequeuereusablecellwithidentifier:@"id"];
if (cell == nil) {
cell = [[uitableviewcell alloc] initwithstyle:uitableviewcellstylevalue1 reuseidentifier:@"id"];
}
if (indexpath.section == 0) {
cell.textlabel.text = [ditailname objectatindex:indexpath.row];
}
if (indexpath.section == 1) {
cell.textlabel.text = @"显示更多";
cell.textlabel.textalignment = nstextalignmentcenter;
}
return cell;
}
- (nsinteger)tableview:(uitableview *)tableview numberofrowsinsection:(nsinteger)section {
if (section == 0) {
if (rownumber > [ditailname count]) {//显示到最多的时候
return [ditailname count];
}
return rownumber;
} else
return 1;
}
- (nsinteger)numberofsectionsintableview:(uitableview *)tableview {
return 2;
}
- (void)tableview:(uitableview *)tableview didselectrowatindexpath:(nsindexpath *)indexpath {
if (indexpath.section == 1) {
rownumber += 20;
[tableview reloaddata];
} else {
nslog(@"---跳转到另外一个页面----");
}
}
- (void)didreceivememorywarning
{
[super didreceivememorywarning];
// dispose of any resources that can be recreated.
}
/*
#pragma mark - navigation
// in a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareforsegue:(uistoryboardsegue *)segue sender:(id)sender
{
// get the new view controller using [segue destinationviewcontroller].
// pass the selected object to the new view controller.
}
*/
@end

以上内容是小编给大家介绍的ios开发之tableview点击行跳转并带有“显示”更多功能,有问题欢迎各位给我留言,我会及时和大家取得联系的,同时感谢大家一直以来对服务器之家网站的支持。

延伸 · 阅读

精彩推荐
  • IOS谈一谈iOS单例模式

    谈一谈iOS单例模式

    这篇文章主要和大家谈一谈iOS中的单例模式,单例模式是一种常用的软件设计模式,想要深入了解iOS单例模式的朋友可以参考一下...

    彭盛凇11872021-01-19
  • IOSiOS10 Xcode8适配7个常见问题汇总

    iOS10 Xcode8适配7个常见问题汇总

    这篇文章主要为大家详细汇总了iOS10 Xcode8适配7个常见问题,具有一定的参考价值,感兴趣的小伙伴们可以参考一下...

    索马里猫10332021-02-01
  • IOSiOS常见的几个修饰词深入讲解

    iOS常见的几个修饰词深入讲解

    这篇文章主要给大家介绍了关于iOS常见的几个修饰词的相关资料,iOS修饰词包括assign、weak、strong、retain、copy、nonatomic、atomic、readonly、readwrite,文中通过示...

    郡王丶千夜7422021-05-10
  • IOSxcode8提交ipa失败无法构建版本问题的解决方案

    xcode8提交ipa失败无法构建版本问题的解决方案

    xcode升级到xcode8后发现构建不了新的版本。怎么解决呢?下面小编给大家带来了xcode8提交ipa失败无法构建版本问题的解决方案,非常不错,一起看看吧...

    Cinna丶7542021-02-03
  • IOSIOS网络请求之AFNetWorking 3.x 使用详情

    IOS网络请求之AFNetWorking 3.x 使用详情

    本篇文章主要介绍了IOS网络请求之AFNetWorking 3.x 使用详情,小编觉得挺不错的,现在分享给大家,也给大家做个参考。一起跟随小编过来看看吧...

    总李写代码6892021-03-04
  • IOSiOS中时间与时间戳的相互转化实例代码

    iOS中时间与时间戳的相互转化实例代码

    这篇文章主要介绍了iOS中时间与时间戳的相互转化实例代码,非常具有实用价值,需要的朋友可以参考下。...

    张无忌!4812021-03-09
  • IOSiOS APP实现微信H5支付示例总结

    iOS APP实现微信H5支付示例总结

    这篇文章主要介绍了iOS APP实现微信H5支付示例总结,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下...

    一张小A11332021-06-01
  • IOSiOS逆向教程之logify跟踪方法的调用

    iOS逆向教程之logify跟踪方法的调用

    这篇文章主要给大家介绍了关于iOS逆向教程之logify跟踪方法调用的相关资料,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学...

    Mr.Guo11472021-04-28