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

 更新时间:2016年03月08日 11:09:48   作者:Livia.Chen  
这篇文章给大家介绍通过点击城市中的tableView跳转到旅游景点的tableView,下面会有“显示”更多的功能,代码简单易懂,对ios点击tableview跳转相关知识感兴趣的朋友一起学习吧

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

一,工程图。


二,代码。

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

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

相关文章

  • IOS中UIWebView加载Loading的实现方法

    IOS中UIWebView加载Loading的实现方法

    最近有朋友问我类似微信语音播放的喇叭动画和界面图片加载loading界面是怎样实现的,是不是就是一个gif图片呢!我的回答当然是否定了,当然不排除也有人用gif图片啊!
    2015-05-05
  • IOS开发之适配iOS10及Xcode8的注意点

    IOS开发之适配iOS10及Xcode8的注意点

    这篇文章主要介绍了IOS开发之适配iOS10及Xcode8的注意点,本文给大家介绍了可能出现的问题及相应的解决方法,非常不错具有参考借鉴价值,感兴趣的朋友一起看看
    2016-10-10
  • 详解iOS webview加载时序和缓存问题总结

    详解iOS webview加载时序和缓存问题总结

    本篇文章主要介绍了iOS webview加载时序和缓存问题总结 ,这两天学习了Vue.js 感觉组件这个地方知识点挺多的,而且很重要,所以,今天添加一点小笔记。
    2017-09-09
  • 详解IOS点击空白处隐藏键盘的几种方法介绍

    详解IOS点击空白处隐藏键盘的几种方法介绍

    本篇文章主要介绍了IOS点击空白处隐藏键盘的几种方法,非常具有实用价值,需要的朋友可以参考下。
    2016-12-12
  • iOS使用CoreMotion实现摇一摇功能

    iOS使用CoreMotion实现摇一摇功能

    这篇文章主要为大家详细介绍了iOS使用CoreMotion实现摇一摇功能,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
    2018-06-06
  • iOS微信浏览器回退不刷新实例(监听浏览器回退事件)

    iOS微信浏览器回退不刷新实例(监听浏览器回退事件)

    下面小编就为大家带来一篇iOS微信浏览器回退不刷新实例(监听浏览器回退事件)。小编觉得挺不错的,现在就分享给大家,也给大家做个参考。一起跟随小编过来看看吧
    2017-05-05
  • iOS开发之统计Xcode工程的代码行数

    iOS开发之统计Xcode工程的代码行数

    这篇文章主要给大家介绍了在iOS开发中,如果想要统计Xcode工程的代码行数该如何实现,文章给出了详细的方法和示例代码,对大家的理解和学习很有帮助,本文中还分享了统计java文件和xml文件的代码,有需要的朋友们下面来一起看看吧。
    2016-10-10
  • iOS tableView实现单选和多选的实例代码

    iOS tableView实现单选和多选的实例代码

    本篇文章主要介绍了iOS tableView实现单选和多选的实例代码,小编觉得挺不错的,现在分享给大家,也给大家做个参考。一起跟随小编过来看看吧
    2017-07-07
  • iOS逆向开发之微信自动添加好友功能

    iOS逆向开发之微信自动添加好友功能

    这篇文章主要介绍了iOS逆向开发之微信自动添加好友功能,非常不错,具有一定的参考借鉴价值,需要的朋友可以参考下
    2019-04-04
  • 简单谈谈c/c++中#import、#include和@class的区别

    简单谈谈c/c++中#import、#include和@class的区别

    对于#import,我想做过iOS开发的人应该都不陌生。在开发过程中,当我们需要声明某一个类时,都需要去引用。而#imclude的话,在我们学习C时就已经知道了,他的作用也是引用声明的意思。在表面上他们的作用似乎都是一样的。但是在具体功能实现方式上,还是有着很大的区别。
    2018-01-01

最新评论