点击城市中的tableView跳转到旅游景点

初始化时候的效果图:

点击单元格后的效果图:

项目目录:

plist截图:

RootViewController.h

#import <UIKit/UIKit.h>

@interface RootViewController : UIViewController
<UITableViewDelegate,UITableViewDataSource>
{
    UITableView * _tableView;
    NSMutableArray * provinceArray;
}

@end

RootViewController.m

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

DetailViewControll.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

DetailViewControl.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(@"---跳转到另外一个页面----");
    }
}
时间: 2024-08-28 10:51:06

点击城市中的tableView跳转到旅游景点的相关文章

easui datagrid 行获取后台sql所有数据:支持行chockbox多选,输出选中行任意属性;支持点击表中属性实现跳转;支持分页。

easyUI datagrid 代码: <table id="tabgrid20170726191838251403" class="easyui-datagrid" params="fit:true,border:false,selectOnCheck:true,remoteSort:false, url:'http://localhost:8090/gzdbthreeweb/engine/loadQueryData.pt?_queryid=201

美团HD(9)-监听点击城市

DJSelectCityViewController.h // 点击城市发出通知 - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { // 1. 发送点击的城市名 DJCityGroup *cityGroup = self.cityGroups[indexPath.section]; [[NSNotificationCenter defaultCenter] p

php开发中的页面跳转方法总结

PHP页面跳转实现的功能就是将网站中一个网页跳转到另一个网页中.对于刚刚学习PHP语言的朋友来说,是必须要掌握的基础方法. 页面跳转可能是由于用户单击链接.按钮等触发的,也可能是系统自动产生的.页面自动跳转在WEB开发中经常用到,而且根据需求可以采用不同的跳转方式,比如提示操作信息后延时跳转等, 本文总结了WEB开发中常见的几种页面跳转方法. PHP header()函数跳转 PHP的header()函数非常强大,其中在页面url跳转方面也调用简单,使用header()直接跳转到指定url页面,

asp.net 中的错误跳转 customerrors 对html文件不起作用

在配置web.config时发现customerrors对aspx文件是起作用的,我想通过customerrors来判断是否有html文件时,却不起作用? 这是为什么,如果要起作用.net里该如何操作? 之所以aspx有用,而html没用是因为iis里的配置里设定了*.aspx,*.config等文件由aspnet_isapi.dll来处理而html默认是不处理, 直接发送给客户端如果你希望html也由aspnet_isapi.dll处理,可以去设置但是这样,html的响应速度也会变慢,因为每个

button按钮触发点击事件后出现自动跳转问题

在项目中遇到在点击+号按钮后出现跳转.该button在form表单内,分析原因得知,触发事件后button按钮自动提交了表单,从而出现跳转. 查找手册得知button type有三个属性值,其中默认为submit,所以在未添加type属性时,button默认为submit. 此问题在button中添加type="button"则恢复正常. 值 描述 submit 默认.按钮是提交按钮. button 按钮时可点击的按钮. reset 按钮是重置按钮(清空数据). 原文地址:https:

如何在Vue项目中给路由跳转加上进度条

1.前言 在平常浏览网页时,我们会注意到在有的网站中,当点击页面中的链接进行路由跳转时,页面顶部会有一个进度条,用来标示页面跳转的进度(如下图所示).虽然实际用处不大,但是对用户来说,有个进度条会大大减轻用户的等待压力,提升用户体验.本篇文章就来教你如何在Vue项目中实现这样的进度条. 2.安装Nprogress 虽然我们也可以自己手动实现这样的功能,但是,nprogress.js已经帮我们把进度条的样式呀,功能呀都已经封装的很好了,既然有现成的轮子,我们就直接使用轮子就好啦! npm inst

ngRoute+ngAnimate与JQM中的页面跳转的区别

1.ngRoute+ngAnimate与jQM中的页面跳转有何异同? 相同点: (1)完整的HTML只需要一个 (2)使用异步AJAX请求获取下一个页面 (3)可以实现转场动画 不同点: (1)ngRoute需要配置路由字典:jQM没有,更加灵活 (2)ngRoute访问路由地址的格式——特殊格式的hash http://xxx/index.html#/main jQM访问页面地址——普通的URL http://xxx/tpl/main.html (3)ngRoute访问的路由页面可以使用F5刷

Swift中使用presentViewController跳转页面后模拟器显示黑屏问题

Swift中使用presentViewController跳转页面后模拟器显示黑屏问题 问题原因 针对storyboard制作页面和手写页面,需要使用两种不同方法进行页面跳转. 解决办法 针对手写页面及storyboard制作页面,使用代码进行页面跳转的两种方法. 对于使用storyboard制作的页面 var sb = UIStoryboard(name: "Main", bundle:nil) var vc = sb.instantiateViewControllerWithIde

iframe中的各种跳转方法

iframe中的各种跳转方法(转) 一.背景A,B,C,D都是jsp,D是C的iframe,C是B的iframe,B是A的iframe,在D中跳转页面的写法区别如下. 二.JS跳转window.location.href.location.href 本页面跳转,D页面跳转parent.location.href 上一层页面跳转,C页面跳转top.location.href 最外层页面跳转,A页面跳转 三.链接或者formD页面中有form < form>: form提交后D页面跳转<fo