一,效果图。

二,工程图。

三,代码。

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

最新文章

  1. C# 一些常用的技巧代码
  2. 部署在IIS上的网站如何调试
  3. Jquery使用ajax以及angularjs 动态模板加载并进行渲染
  4. c语言字符串_续
  5. 增加p()函数,方便开发中对变量打印调试
  6. hibernate相关知识
  7. Android平台的事件处理机制和手指滑动例子
  8. JSP总结1
  9. [置顶] 学习JDK源码:编程习惯和设计模式
  10. JS使用默认图片代替页面上无法显示的图片
  11. 网页设计——6.html其他标签
  12. 【一天一道LeetCode】#18. 4Sum
  13. Appium在Android7.0及以上系统运行时报错的解决方案
  14. MySQL 修改账号的IP限制条件
  15. C#使用ES
  16. MySQL索引底层实现原理
  17. dapper视频
  18. spring mvc 返回乱码SpringMVC使用@ResponseBody注解返回中文字符串乱码的问题
  19. notepad++添加插件管理器
  20. Laravel 本地化定义

热门文章

  1. JS魔法堂:mmDeferred源码剖析
  2. ADO.NET封装的SqlHelper
  3. 十五个常用的jquery代码段
  4. Web API配置自定义路由
  5. 用纯css画个三角形
  6. 基于.Net Framework 4.0 Web API开发(5):ASP.NET Web APIs AJAX 跨域请求解决办法(CORS实现)
  7. JSP读取My SQL数据乱码问题的解决
  8. TabHost的使用
  9. Java程序,JDK的安装、环境的配置
  10. Scalaz(24)- 泛函数据结构: Tree-数据游览及维护