【代码笔记】iOS-点击城市中的tableView跳转到旅游景点的tableView,下面会有“显示”更多。...
                                                            生活随笔
收集整理的這篇文章主要介紹了
                                【代码笔记】iOS-点击城市中的tableView跳转到旅游景点的tableView,下面会有“显示”更多。...
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.                        
                                一,效果圖。
二,工程圖。
三,代碼。
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顯示行數(shù)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"]];//北京所有數(shù)據(jù)provinceArr = [dicForPlist objectForKey:cityName];for (int j = 0; j < [provinceArr count]; j++) {//遍歷省的所有數(shù)據(jù)cityArray = [provinceArr objectAtIndex:j];//取出每一個小數(shù)組for (int i = 0; i < [cityArray count]; i++) {//遍歷小數(shù)組NSString* strstr = [cityArray objectAtIndex:i]; //得到小數(shù)組內(nè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
創(chuàng)作挑戰(zhàn)賽新人創(chuàng)作獎勵來咯,堅持創(chuàng)作打卡瓜分現(xiàn)金大獎總結
以上是生活随笔為你收集整理的【代码笔记】iOS-点击城市中的tableView跳转到旅游景点的tableView,下面会有“显示”更多。...的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
 
                            
                        - 上一篇: 支付宝手机h5网页支付不再提供「继续浏览
- 下一篇: css之文本溢出处理 | 背景图片处理
