[Code Note] Click tableView in the city to jump to the tableView of a tourist attraction. "Show" is displayed below ., Tableview jump
I ,.
2. Engineering Drawing.
3. Code.
RootViewController. h
#import <UIKit/UIKit.h>@interface RootViewController : UIViewController<UITableViewDelegate,UITableViewDataSource>{ UITableView * _tableView; NSMutableArray * provinceArray;}@end
RootViewController. m
# Import "RootViewController. h "// detailed page # import" DetailViewController. h "@ interface RootViewController () @ end @ implementation RootViewController-(id) initWithNibName :( NSString *) bundle :( NSBundle *) handle {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: @ "Beijing", @ "Shanghai", @ "Yunnan", @ "Sichuan", @ "Hainan", @ "Jiangsu ", @ "Hong Kong", @ "Macao", @ "Tibet", nil]; _ tableView = [[UITableView alloc] initWithFrame: CGRectMake (0, 0,320,380) style: UITableViewStyleGrouped]; _ tableView. delegate = self; _ tableView. dataSource = self; [self. view addSubview: _ tableView] ;}# pragma-mark-Example-(UITableViewCell *) tableView :( UITableView *) tableView cellForRowAtIndexPath :( NSIndexPath *) indexPath {UITableViewCell * cell = [tableView progress: @ "ID"]; if (cell = nil) {cell = [[UITableViewCell alloc] initWithStyle: UITableViewCellStyleValue1 reuseIdentifier: @ "ID"];} cell. textLabel. text = [provinceArray objectAtIndex: indexPath. row]; cell. accessoryType = response; return cell;}-(NSInteger) tableView :( UITableView *) tableView numberOfRowsInSection :( NSInteger) section {return 9;}-(CGFloat) tableView :( UITableView *) tableView heightForRowAtIndexPath :( NSIndexPath *) indexPath {return 60;} // click to enter the next page-(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 didreceivemorywarning]; // 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 *) handle {self = [super initWithNibName: nibNameOrNil bundle: nibBundleOrNil]; if (self) {// Custom initialization} return self;}-(void) viewDidLoad {[super viewDidLoad]; // Do any additional setup afte R loading the view. // The Name Of The city passed in: cityName = self. title; // number of rows displayed in 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]; // city plist file dicForPlist = [NSDictionary dictionaryWithContentsOfFile: [[NSBundle mainBundle] pathForResource: @ "cityName" ofType: @ "plist"]; // all data in Beijing: provinceArr = [dicForPlist objectForKey: cityName]; for (int j = 0; j <[provinceArr count]; j ++) {// retrieve all provincial data cityArray = [provinceArr objectAtIndex: j]; // retrieve each small array for (int I = 0; I <[cityArray count]; I ++) {// traverse the small array NSString * strstr = [cityArray ObjectAtIndex: I]; // get the small array content if ([strstr isw.tostring: 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 isw.tostring: cityName] & j + 1 = [provinceArr count]) {NSLog (@ "last one? ") ;}}# Pragma-mark-UITableViewDelegate-(UITableViewCell *) tableView :( UITableView *) tableView cellForRowAtIndexPath :( NSIndexPath *) indexPath {UITableViewCell * cell = [tableView progress: @ "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 = @ "show more"; 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 (@ "--- jump to another page ----") ;}}-(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