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开发中取消文本框输入时的小键盘

    IOS开发中取消文本框输入时的小键盘

    这篇文章主要介绍了IOS开发中取消文本框输入时的小键盘,需要的朋友可以参考下
    2015-05-05
  • 解决ios audio无法播放问题

    解决ios audio无法播放问题

    这篇文章主要介绍了解决ios audio无法播放问题,并给大家分享了解决方法,需要的朋友参考一下。
    2017-11-11
  • iOS自定义转场动画的几种情况

    iOS自定义转场动画的几种情况

    这篇文章主要给大家介绍了关于iOS自定义转场动画的几种情况,文中通过示例代码介绍的非常详细,对各位iOS开发者们具有一定的参考学习价值,需要的朋友们下面来一起学习学习吧
    2019-06-06
  • 个人对于异步和多线程的关系的理解分享

    个人对于异步和多线程的关系的理解分享

    异步和多线程并不是一个同等关系,异步是最终目的,多线程只是我们实现异步的一种手段。异步是当一个调用请求发送给被调用者,而调用者不用等待其结果的返回而可以做其它的事情。
    2014-08-08
  • iOS - UIButton(UIEdgeInsets)/设置button上的文字和图片上下垂直居中对齐

    iOS - UIButton(UIEdgeInsets)/设置button上的文字和图片上下垂直居中对齐

    这篇文章主要介绍了iOS - UIButton(UIEdgeInsets)/设置button上的文字和图片上下垂直居中对齐的相关资料,需要的朋友可以参考下
    2015-09-09
  • IOS开发实现录音功能

    IOS开发实现录音功能

    本文给大家分享的是一个IOS开发中实现录音功能的实例,并简单给大家解析一下,有需要的小伙伴可以参考下
    2016-03-03
  • IOS中UITextView或UITextField字数限制的实现

    IOS中UITextView或UITextField字数限制的实现

    这篇文章主要介绍了IOS中UITextView或UITextField字数限制的实现的相关资料,希望通过本文能帮助到大家实现这样的功能,需要的朋友可以参考下
    2017-10-10
  • IOS中内存管理那些事

    IOS中内存管理那些事

    这篇文章主要介绍了IOS中内存管理那些事的相关资料,需要的朋友可以参考下
    2015-11-11
  • 百度地图PC端判断用户是否在配送范围内

    百度地图PC端判断用户是否在配送范围内

    在pc端设置商家的配送范围,用户在下单时,根据用户设置的配送地点判断是否在可配送范围内,并给用户相应的提示,下面通过本文给大家分享具有实现代码,感兴趣的朋友一起学习吧
    2016-01-01
  • iOS实现无限滑动效果

    iOS实现无限滑动效果

    这篇文章主要为大家详细介绍了iOS实现无限滑动效果,文中示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
    2022-03-03

最新评论