一,效果图。

二,工程图。

三,代码。

RootViewController.h

#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

#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

#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;} elsereturn 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

 
 

转载于:https://www.cnblogs.com/yang-guang-girl/p/5252900.html

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

  1. idea2020.3配置点击mapper中的方法跳转到对应得xml中

    idea2020.3配置点击mapper中的方法跳转到对应得xml中 在settings中找到Plugins,搜索"Free MyBatis plugin",然后点击Install ...

  2. HTML5期末大作业:旅游景点网站设计——成都(6页) HTML+CSS+JavaScript 大学生家乡网页设计作业模板下载 四川成都城市网页设计作业成品 静态HTML旅游景点网页制作下载...

    HTML5期末大作业:旅游景点网站设计--成都(6页) HTML+CSS+JavaScript 学生DW网页设计作业成品 web课程设计网页规划与设计 计算机毕设网页设计源码 常见网页设计作业题材有 ...

  3. HTML5期末大作业:旅游景点网站设计——成都(6页) HTML+CSS+JavaScript 大学生家乡网页设计作业模板下载 四川成都城市网页设计作业成品 静态HTML旅游景点网页制作下载

    HTML5期末大作业:旅游景点网站设计--成都(6页) HTML+CSS+JavaScript 学生DW网页设计作业成品 web课程设计网页规划与设计 计算机毕设网页设计源码 常见网页设计作业题材有 ...

  4. 【代码笔记】iOS-在导航栏中显示等待对话框

    一,效果图. 二,代码. ViewController.m #import "ViewController.h"@interface ViewController () @end ...

  5. html表格添加选项代码,使用实例演示 表单 中的选项卡功能 在里面添加table id=bootstrap-table/table后不显示表格...

    .time-input{ display: inline; } .add-right{ float: right; font-size: 20px; border: 1px solid #111111 ...

  6. 小程序嵌入web-view网页后,点击网页中的按钮跳转回小程序

    1.首先在网页端引入js <script type="text/javascript" src="https://res.wx.qq.com/open/js/jwe ...

  7. 平台游戏中走与跳的实现

    内容简述: 平台游戏中,如何在动作操作方面达到<Celeste>,<死亡细胞>等作品那样的效果(手感),单纯使用物理引擎是比较难做到的,因为我们需要一些反常识的运动效果,而这些 ...

  8. iOS点击短信中的链接跳转到App

    现在有这样一个需求:用户点击短信上的链接跳转到我们的App中或者App中的指定页面. 可行的方案大概有三种: 一.直接使用URL Scheme.(优点:十分简单,在plist文件中配置一个scheme ...

  9. 2022 最新 Android 基础教程,从开发入门到项目实战【b站动脑学院】学习笔记——第五章:中级控件

    第 5 章 中级控件 本章介绍App开发常见的几类中级控件的用法,主要包括:如何定制几种简单的图形.如何使用几种选择按钮.如何高效地输入文本.如何利用对话框获取交互信息等,然后结合本章所学的知识,演示 ...

最新文章

  1. linux内核杂记(9)-进程调度(4)
  2. php增加mysql用户_mysql 增加用户
  3. 大数据的说法 正确的是_数据量——让数据分析师永远头疼的指标
  4. Mac下快速新建txt文件
  5. HDF5: Python 的h5py与Julia的HDF5库读取效率比较,不差上下
  6. dos如何运行java_怎么用DOS命令运行java程序
  7. 软件开发公司能开发哪些类型的app软件
  8. java jcmd,jcmd命令用法
  9. java mysql 流水号_java实现数据库序号(流水号)
  10. 网络接入与身份认证简介
  11. 实现LAYERED窗口
  12. Android 11.0 12.0关机界面全屏显示(UI全屏显示)
  13. Claude Shannon 的“创新性思维”演讲:一个天才揭示如何变得具有创新性
  14. AndroidQ 分屏窗口尺寸计算 (WMS部分)
  15. 天下大事,必做于细!
  16. 一张老照片上看故乡内江
  17. 家里装电线时,为啥说“走顶”比“走地”好
  18. 阿里云云服务器ECS选购指南及省钱法宝
  19. matlab中定义类、面向对象编程
  20. Echarts2.27树图和Handler.aspx结合

热门文章

  1. 简单使用Git和Github来管理自己的代码和读书笔记
  2. koa --- [MVC实现之四]Router、Controller、Service的实现
  3. vue --- 前端代理发送http请求
  4. 算法 --- 二叉树的最大深度
  5. ES6-4/5 解构赋值、函数默认值、数组解构、对象解构
  6. OC Swift混编-Swift.h File not found
  7. BZOJ 2440 完全平方数(莫比乌斯-容斥原理)
  8. 我的一点企业做云经验
  9. 简单实现仿某宝地址选择三级联动样式
  10. Python实现atm机的功能