本节书摘来自异步社区《iPad开发从入门到精通》一书中的第6章,第6.2节系统主界面,作者 杨春泽,更多章节内容可以访问云栖社区“异步社区”公众号查看
6.2 系统主界面iPad开发从入门到精通本章实例的的源码保存在“:daima6Bus”,默认的系统主界面是线路查询视图,在线路查询视图CBus_LineView.xib顶部设置了一个查询表单,在下方列表显示系统内的公交线路。线路查询视图的UI界面如图6-1所示。
6.2.1 线路查询视图实现文件CBus_LineViewController.h的代码如下所示。
#import <UIKit/UIKit.h> @interface CBus_LineViewController : UIViewController <UITableViewDelegate, UITableViewDataSource,UISearchDisplayDelegate, UISearchBarDelegate>{ UITableView *busLineTableView; NSMutableArray *filteredListContent; } @property(nonatomic, retain) IBOutlet UITableView *busLineTableView; @property(nonatomic, retain) NSMutableArray *filteredListContent; @end 文件CBus_LineViewController.m是文件CBus_LineViewController.h的实现,功能是载入设置的视图界面,显示一个搜索表单,并在表单下方列表显示30条公交线路信息,并且可以根据用户输入的搜索关键字来显示搜索结果。文件CBus_LineViewController.m的具体实现代码如下所示。 #import "CBus_LineViewController.h" #import "CBus_LineDetailViewController.h" #import "CDataContainer.h" @implementation CBus_LineViewController @synthesize busLineTableView,filteredListContent; // 通过viewdidload的额外设置后加载视图 - (void)viewDidLoad { [super viewDidLoad]; self.filteredListContent = [NSMutableArray arrayWithCapacity:[[CDataContainer Instance].lineNameArray count]]; } #pragma mark - #pragma mark View lifecycle - (void)viewWillAppear:(BOOL)animated { [super viewWillAppear:animated]; [self.busLineTableView reloadData]; NSLog(@"-----Nav------%@",self.navigationController.viewControllers); NSUserDefaults *userDefault = [NSUserDefaults standardUserDefaults]; NSInteger styleNum = [userDefault integerForKey:@"styleType"]; switch (styleNum) { case 0:{ [UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleDefault; self.navigationController.navigationBar.barStyle = UIBarStyleDefault; self.searchDisplayController.searchBar.barStyle = UIBarStyleDefault; break; } case 1:{ [UIApplication sharedApplication].statusBarStyle = UIStatusBarStyle BlackOpaque; self.navigationController.navigationBar.barStyle = UIBarStyleBlackOpaque; self.searchDisplayController.searchBar.barStyle = UIBarStyleBlackOpaque; break; } } [self.busLineTableView reloadData]; } - (void)viewDidAppear:(BOOL)animated { [super viewDidAppear:animated]; } #pragma mark - #pragma mark Table view data source - (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section{ return @"公交线路"; } - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{ return 30; } - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { // Return the number of sections return 1; } - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { // 返回行数 if(tableView == self.searchDisplayController.searchResultsTableView){ return [filteredListContent count]; } else { return [[CDataContainer Instance].lineNameArray count]; } } // 自定义表格单元的外观 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *CellIdentifier = @"Cell"; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; if (cell == nil) { cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease]; } cell.selectionStyle = UITableViewCellSelectionStyleGray; // 配置单元… if (tableView == self.searchDisplayController.searchResultsTableView){ [[CDataContainer Instance] GetLineStationFromTableSequence: [[CDataContainer Instance].lineNameArray indexOfObject: [filteredListContent objectAtIndex:indexPath.row]]]; NSString *beginStr = [[CDataContainer Instance].stationNameArray objectAtIndex: [[CDataContainer Instance] GetBusLineSequence ByIndex:0]-1]; NSString *endStr = [[CDataContainer Instance].stationNameArray objectAtIndex: [[CDataContainer Instance] GetBusLineSequence ByIndex:[[CDataContainer Instance].sequenceNumArray count]-1]-1]; NSString *detailStr = [[NSString alloc] initWithFormat:@"%@-->%@",beginStr,endStr]; cell.detailTextLabel.font = [UIFont systemFontOfSize:12]; cell.detailTextLabel.text = detailStr; [detailStr release]; cell.textLabel.text = [filteredListContent objectAtIndex:indexPath.row]; } else{ [[CDataContainer Instance] GetLineStationFromTableSequence:indexPath.row]; NSString *beginStr = [[CDataContainer Instance].stationNameArray objectAtIndex: [[CDataContainer Instance] GetBusLineSequence ByIndex:0]-1]; NSString *endStr = [[CDataContainer Instance].stationNameArray objectAtIndex: GetBusLineSequenceByIndex:[[CDataContainer Instance].sequenceNumArray count]-1]-1]; NSString *detailStr = [[NSString alloc] initWithFormat:@"%@-->%@",beginStr, endStr]; cell.detailTextLabel.font = [UIFont systemFontOfSize:12]; cell.detailTextLabel.text = detailStr; [detailStr release]; cell.textLabel.text = [[CDataContainer Instance].lineNameArray objectAtIndex: indexPath.row]; } cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator; cell.imageView.image = [UIImage imageNamed:@"bus_table_line.png"]; return cell; } #pragma mark - #pragma mark Table view delegate - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{ // 创造和推动另一个视图控制器 CBus_LineDetailViewController *detailViewController = [[CBus_LineDetailViewController alloc] initWithNibName:@"CBus_LineDetailView" bundle:nil]; // 选定的对象到新视图控制器 if (tableView == self.searchDisplayController.searchResultsTableView){ detailViewController.currentLineName = [filteredListContent objectAtIndex: indexPath.row]; detailViewController.currentLineIndex = [[CDataContainer Instance].lineName Array indexOfObject:[filteredListContent objectAtIndex:indexPath.row]]; } else{ detailViewController.currentLineName = [[CDataContainer Instance].lineName Array objectAtIndex:indexPath.row]; detailViewController.currentLineIndex = indexPath.row; } [self.navigationController pushViewController:detailViewController animated:YES]; [detailViewController release]; } #pragma mark - #pragma mark Content Filtering - (void)filterContentForSearchText:(NSString*)searchText scope:(NSString*)scope{ /* 基于搜索文本和范围更新过滤阵列 */ // 清除过滤数组 [self.filteredListContent removeAllObjects]; /* 主要搜索与列表类型相匹配的范围,其名字要匹配比赛查找的文字;添加与项目匹配的过滤阵列 */ for (int i = 0; i < [[CDataContainer Instance].lineNameArray count]; i++){ NSString * searchInfo = [[CDataContainer Instance].lineNameArray objectAtIndex:i]; NSComparisonResult result = [searchInfo compare:searchText options:(NSCaseInsensitiveSearch|NSDiacriticInsensitiveSearch) range:NSMakeRange(0, [searchText length])]; if (result == NSOrderedSame){ [self.filteredListContent addObject:searchInfo]; } } } #pragma mark - #pragma mark UISearchDisplayController Delegate Methods - (BOOL)searchDisplayController:(UISearchDisplayController *)controller shouldReload TableForSearchString:(NSString *)searchString{ [self filterContentForSearchText:searchString scope: [[self.searchDisplayController.searchBar scopeButtonTitles] objectAtIndex:[self. searchDisplayController.searchBar selectedScopeButtonIndex]]]; // 重新加载返回的搜索结果 return YES; } - (BOOL)searchDisplayController:(UISearchDisplayController *)controller shouldReload TableForSearchScope:(NSInteger)searchOption{ [self filterContentForSearchText:[self.searchDisplayController.searchBar text]scope: [[self.searchDisplayController.searchBar scopeButtonTitles] objectAtIndex: searchOption]]; // Return YES to cause the search result table view to be reloaded return YES; } // Override to allow orientations other than the default portrait orientation - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrien tation{ // Return YES for supported orientations return (interfaceOrientation == UIInterfaceOrientationPortrait); } - (void)didReceiveMemoryWarning { // Releases the view if it doesn't have a superview [super didReceiveMemoryWarning]; self.busLineTableView = nil; } - (void)viewDidUnload { [super viewDidUnload]; // Release any retained subviews of the main view // e.g. self.myOutlet = nil; } - (void)dealloc { [busLineTableView release]; [filteredListContent release]; [super dealloc]; } @end执行效果如图6-2所示。
6.2.2 线路详情模块本模块的功能是显示某一条线路的详细信息,在上方显示线路名、票价、首班时间和末班时间,在下方列表显示各个站点。线路详情视图CBus_LineDetailView.xib的UI界面如图6-3所示。
实现文件 CBus_LineDetailViewController.h的代码如下所示。
#import <UIKit/UIKit.h> enum ERunType{ EUpLineType, EDownLineType, ENoneLineType }; @interface CBus_LineDetailViewController : UIViewController <UITableViewDelegate, UITableViewDataSource>{ UITableView *busLineDetailTableView; //当前查询线路的index NSInteger currentLineIndex; NSString *currentLineName; NSInteger runType; NSMutableArray *upLineArray; NSMutableArray *downLineArray; } @property(nonatomic, retain) IBOutlet UITableView *busLineDetailTableView; @property(nonatomic, retain) NSString *currentLineName; @property(nonatomic) NSInteger currentLineIndex; -(void)AddLineToFavorite; @end 文件CBus_LineDetailViewController.m是CBus_LineDetailViewController.h的实现,功能是显示某条线路的详细信息,它不但列表显示了此线路中的各个站点,而且实现了收藏功能。文件CBus_LineDetailViewController.m的具体实现代码如下所示。 #import "CBus_LineDetailViewController.h" #import "CBus_StationDetailViewController.h" #import "CBus_LineDetailLineViewController.h" #import "CDataContainer.h" @implementation CBus_LineDetailViewController @synthesize busLineDetailTableView,currentLineName; @synthesize currentLineIndex; // 载入界面 - (void)viewDidLoad { [super viewDidLoad]; self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithBar ButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(AddLineToFavorite)]; [[CDataContainer Instance] GetLineStationFromTableSequence:currentLineIndex]; } #pragma mark - #pragma mark View lifecycle - (void)viewWillAppear:(BOOL)animated{ [super viewWillAppear:animated]; [self.busLineDetailTableView reloadData]; NSUserDefaults *userDefault = [NSUserDefaults standardUserDefaults]; NSInteger styleNum = [userDefault integerForKey:@"styleType"]; switch (styleNum) { case 0:{ [UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleDefault; self.navigationController.navigationBar.barStyle = UIBarStyleDefault; self.searchDisplayController.searchBar.barStyle = UIBarStyleDefault; break; } case 1:{ [UIApplication sharedApplication].statusBarStyle = UIStatusBarStyle BlackOpaque; self.navigationController.navigationBar.barStyle = UIBarStyleBlackOpaque; self.searchDisplayController.searchBar.barStyle = UIBarStyleBlackOpaque; break; } } [[CDataContainer Instance] GetLineStationFromTableSequence:currentLineIndex]; [self.busLineDetailTableView reloadData]; NSLog(@"-----Nav----%@",self.navigationController.viewControllers); } - (void)viewDidDisappear:(BOOL)animated { [super viewDidDisappear:animated]; } -(void)AddLineToFavorite { NSLog(@"-------addLineToFavorite---------%@---%d",currentLineName,currentLineIndex); for(NSString *lineName in [CDataContainer Instance].favoriteLineNameArray){ if ([lineName isEqualToString:currentLineName]) { UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"收藏" message:[NSString stringWithFormat:@"%@ 已收藏",currentLineName]delegate:selfcancel ButtonTitle:@"确定"otherButtonTitles:nil]; [alert show]; [alert release]; return; } } [[CDataContainer Instance] InsertFavoriteInfoToDatabase:0 AddName:currentLineName AddIndex:currentLineIndex AddNameEnd:nil AddIndexEnd:0]; UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"收藏" message:[NSString stringWithFormat:@"收藏 %@ 成功",currentLineName]delegate:selfcancel ButtonTitle:@"确定" otherButtonTitles:nil]; [alert show]; [alert release]; } #pragma mark - #pragma mark Table view data source - (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section{ return currentLineName; } - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{ return 30; } - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { // Return the number of sections return 1; } - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{ // 返回行数. return [[CDataContainer Instance].sequenceNumArray count]; } //自定义表格单元的外观视图 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ static NSString *CellIdentifier = @"Cell"; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; if (cell == nil) { cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease]; } cell.selectionStyle = UITableViewCellSelectionStyleGray; cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator; // 配置单元 cell.textLabel.text = [[CDataContainer Instance].stationNameArray objectAtIndex: [[CDataContainer Instance] GetBusLineSequenceByIndex:indexPath.row]-1]; cell.imageView.image = [UIImage imageNamed:@"bus_table_stat.png"]; return cell; } #pragma mark - #pragma mark Table view delegate - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { // 创造另一个视图控制器 CBus_LineDetailLineViewController *detailViewController = [[CBus_LineDetailLine ViewController alloc] initWithNibName:@"CBus_LineDetailLineView" bundle:nil]; detailViewController.currentStationName = [[CDataContainer Instance].stationNameArray objectAtIndex:[[CDataContainer Instance] GetBusLineSequenceByIndex:indexPath.row]-1]; detailViewController.currentStationIndex = [[CDataContainer Instance].stationNameArray indexOfObject:detailViewController.currentStationName]+1; [self.navigationController pushViewController:detailViewController animated:YES]; [detailViewController release]; } -(void)tableView:(UITableView *)tableView accessoryButtonTappedForRowWithIndexPath:(NSIndexPath *)indexPath{ } // 显示默认线路的图片 - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrien tation { // Return YES for supported orientations return (interfaceOrientation == UIInterfaceOrientationPortrait); } - (void)didReceiveMemoryWarning { //如果没有视图则释放它 [super didReceiveMemoryWarning]; self.busLineDetailTableView = nil; } - (void)viewDidUnload { [super viewDidUnload]; // 释放任何保留的主视图 // e.g. self.myOutlet = nil; } - (void)dealloc { [busLineDetailTableView release]; [super dealloc]; } @end执行效果如图6-4所示。
6.2.3 线路中某站详情本模块的功能是显示某一条线路中某个站的详细信息,显示通过这个站的所有线路。此模块的视图CBus_LineDetailLineView.xib的UI界面如图6-5所示。
实现文件 CBus_LineDetailLineViewController.h的代码如下所示。
#import <UIKit/UIKit.h> @interface CBus_LineDetailLineViewController : UIViewController <UITableViewDelegate, UITableViewDataSource>{ UITableView *busStationDetailView; NSInteger currentStationIndex; NSString *currentStationName; NSInteger beginStationIndex; NSString *beginStationName; NSInteger endStationIndex; NSString *endStationName; BOOL isStatToStat; NSMutableArray *beginStationLineArray; NSMutableArray *endStationLineArray; NSMutableArray *StatToStatLineArray; } @property(nonatomic, retain) IBOutlet UITableView *busStationDetailView; @property(nonatomic, retain) NSString *currentStationName; @property(nonatomic) NSInteger currentStationIndex; @property(nonatomic, retain) NSString *beginStationName; @property(nonatomic) NSInteger beginStationIndex; @property(nonatomic, retain) NSString *endStationName; @property(nonatomic) NSInteger endStationIndex; @property(nonatomic) BOOL isStatToStat; @property(nonatomic, retain) NSMutableArray *beginStationLineArray; @property(nonatomic, retain) NSMutableArray *endStationLineArray; @property(nonatomic, retain) NSMutableArray *StatToStatLineArray; - (BOOL)findTwoStationInOneLine; - (BOOL)findTwoStationInTwoLine; @end 文件CBus_LineDetailLineViewController.m是文件CBus_LineDetailLineViewController.h的实现,具体代码如下所示。 #import "CBus_LineDetailLineViewController.h" #import "CBus_LineDetailViewController.h" #import "CDataContainer.h" @implementation CBus_LineDetailLineViewController @synthesize busStationDetailView; @synthesize currentStationName,currentStationIndex; @synthesize beginStationName,beginStationIndex,endStationName,endStationIndex; @synthesize isStatToStat; @synthesize beginStationLineArray, endStationLineArray, StatToStatLineArray; // 初始化视图 - (void)viewDidLoad{ [super viewDidLoad]; self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithBar ButtonSystemItem:UIBarButtonSystemItemAddtarget:self action:@selector(AddStationToFavorite)]; if (isStatToStat){ NSLog(@"---------isStatToStat-------"); [[CDataContainer Instance] GetStationLineFromTableSequence:beginStationIndex]; beginStationLineArray = [NSMutableArray arrayWithArray:[CDataContainer Instance].stationLineArray]; NSLog(@"---------beginStationLineArray-------%@",beginStationLineArray); [[CDataContainer Instance] GetStationLineFromTableSequence:endStationIndex]; endStationLineArray = [NSMutableArray arrayWithArray:[CDataContainer Instance].stationLineArray]; NSLog(@"---------endStationLineArray-------%@",endStationLineArray); if ([self findTwoStationInOneLine]){ return; } else if([self findTwoStationInTwoLine]){ return; } } else { NSLog(@"---------isStat-------"); [[CDataContainer Instance] GetStationLineFromTableSequence:currentStationIndex]; } } - (BOOL)findTwoStationInOneLine{ NSLog(@"-------findTwoStationInOneLine------"); if (StatToStatLineArray == nil){ StatToStatLineArray = [[NSMutableArray alloc] init]; } for (NSString *beginStationStr in beginStationLineArray){ for(NSString *endStationStr in endStationLineArray){ if ([beginStationStr isEqualToString:endStationStr]){ [StatToStatLineArray addObject:beginStationStr]; NSLog(@"-----------StatToStatLineArray--------%@",StatToStatLineArray); } } } if (StatToStatLineArray){ return YES; } return NO; } - (BOOL)findTwoStationInTwoLine{ return NO; } #pragma mark - #pragma mark View lifecycle - (void)viewWillAppear:(BOOL)animated { [super viewWillAppear:animated]; [self.busStationDetailView reloadData]; NSLog(@"-----Nav----%@",self.navigationController.viewControllers); NSUserDefaults *userDefault = [NSUserDefaults standardUserDefaults]; NSInteger styleNum = [userDefault integerForKey:@"styleType"]; switch (styleNum){ case 0:{ [UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleDefault; self.navigationController.navigationBar.barStyle = UIBarStyleDefault; self.searchDisplayController.searchBar.barStyle = UIBarStyleDefault; break; } case 1:{ [UIApplication sharedApplication].statusBarStyle = UIStatusBarStyle BlackOpaque; self.navigationController.navigationBar.barStyle = UIBarStyleBlackOpaque; self.searchDisplayController.searchBar.barStyle = UIBarStyleBlackOpaque; break; } } } - (void)viewDidDisappear:(BOOL)animated { [super viewDidDisappear:animated]; } -(void)AddStationToFavorite{ NSLog(@"-----AddStationToFavorite-----%@----%d",currentStationName,currentStationIndex); for(NSString *lineName in [CDataContainer Instance].favoriteStationNameArray){ if ([lineName isEqualToString:currentStationName]){ UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"收藏" message:[NSString stringWithFormat:@"%@ 已收藏",currentStationName] delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil]; [alert show]; [alert release]; return; } } [[CDataContainer Instance] InsertFavoriteInfoToDatabase:1 AddName:currentStation Name AddIndex:currentStationIndex AddNameEnd:nil AddIndexEnd:0]; UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"收藏" message:[NSString stringWithFormat:@"收藏 %@ 成功",current StationName] delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil]; [alert show]; [alert release]; } #pragma mark - #pragma mark Table view data source - (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section{ if (isStatToStat){ return [[NSString alloc] initWithFormat:@"%@——>%@",beginStationName,endStationName]; } else{ return currentStationName; } return nil; } - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{ return 30; } - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { // Return the number of sections return 1; } - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{ // Return the number of rows in the section if (isStatToStat){ return [StatToStatLineArray count]; } else{ return [[CDataContainer Instance].stationLineArray count]; } return 0; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ static NSString *CellIdentifier = @"Cell"; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; if (cell == nil){ cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease]; } cell.selectionStyle = UITableViewCellSelectionStyleGray; cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator; if (isStatToStat){ cell.textLabel.text = [[CDataContainer Instance].lineNameArray objectAtIndex: [[StatToStatLineArray objectAtIndex:indexPath.row] intValue]/2-1]; } else{ [[CDataContainer Instance] GetLineStationFromTableSequence: [[CDataContainer Instance].lineNameArray indexOfObject:[[CDataContainer Instance].lineNameArray objectAtIndex:[[CDataContainer Instance] GetBusStationLine ByIndex:indexPath.row]-1]]]; NSString *beginStr = [[CDataContainer Instance].stationNameArray objectAtIndex:[[CDataContainer Instance] GetBusLineSequenceByIndex:0]-1]; NSString *endStr = [[CDataContainer Instance].stationNameArray objectAtIndex: [[CDataContainer Instance] GetBusLineSequence ByIndex:[[CDataContainer Instance].sequenceNumArray count]-1]-1]; NSString *detailStr = [[NSString alloc] initWithFormat:@"%@-->%@",beginStr, endStr]; cell.detailTextLabel.font = [UIFont systemFontOfSize:12]; cell.detailTextLabel.text = detailStr; [detailStr release]; cell.textLabel.text = [[CDataContainer Instance].lineNameArray objectAtIndex: [[CDataContainer Instance] GetBusStation LineByIndex: indexPath.row]-1]; } cell.imageView.image = [UIImage imageNamed:@"bus_table_line.png"]; return cell; } #pragma mark - #pragma mark Table view delegate - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { // Navigation logic may go here. Create and push another view controller. CBus_LineDetailViewController *lineDetailViewController = [self.navigation Controller.viewControllers objectAtIndex:1]; lineDetailViewController.currentLineName = [[CDataContainer Instance]. lineNameArray objectAtIndex:[[CDataContainer Instance] GetBusStationLineByIndex: indexPath.row]-1]; lineDetailViewController.currentLineIndex = [[CDataContainer Instance] .lineNameArray indexOfObject:lineDetailViewController.currentLineName]; [self.navigationController popViewControllerAnimated:YES]; } // Override to allow orientations other than the default portrait orientation - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrien tion { // Return YES for supported orientations return (interfaceOrientation == UIInterfaceOrientationPortrait); } - (void)didReceiveMemoryWarning { // Releases the view if it doesn't have a superview [super didReceiveMemoryWarning]; // Release any cached data, images, etc. that aren't in use } - (void)viewDidUnload { [super viewDidUnload]; // Release any retained subviews of the main view. // e.g. self.myOutlet = nil; } - (void)dealloc { [busStationDetailView release]; [super dealloc]; } @end 相关资源:敏捷开发V1.0.pptx