《iPad开发从入门到精通》——6.2节系统主界面-阿里云开发者社区

开发者社区> 异步社区> 正文

《iPad开发从入门到精通》——6.2节系统主界面

简介:
+关注继续查看

本节书摘来自异步社区《iPad开发从入门到精通》一书中的第6章,第6.2节系统主界面,作者 杨春泽,更多章节内容可以访问云栖社区“异步社区”公众号查看

6.2 系统主界面
iPad开发从入门到精通
本章实例的的源码保存在“:daima6Bus”,默认的系统主界面是线路查询视图,在线路查询视图CBus_LineView.xib顶部设置了一个查询表单,在下方列表显示系统内的公交线路。线路查询视图的UI界面如图6-1所示。


856b5058900330653d4b73a95d828cb574ea715b

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所示。


c95f3dfce4ef3384cad751f919583cb1cd640d11

6.2.2 线路详情模块
本模块的功能是显示某一条线路的详细信息,在上方显示线路名、票价、首班时间和末班时间,在下方列表显示各个站点。线路详情视图CBus_LineDetailView.xib的UI界面如图6-3所示。


47021e41ffe851fb890f2d4c4fafc3a4b9eacc03

实现文件 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所示。


d924b3e9e00a17af947786383e089e852050c5f3

6.2.3 线路中某站详情
本模块的功能是显示某一条线路中某个站的详细信息,显示通过这个站的所有线路。此模块的视图CBus_LineDetailLineView.xib的UI界面如图6-5所示。


b100920746e39be6961155affde468d3fd5fce6c

实现文件 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

版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。

相关文章
iOS(iPhone/iPad)开发新手必读
Objective-C 入门 一个简单的可以快速上手的 Objective-C 入门教程。 iOS概述 本文对构成iOS的基础特性提供了高层的概述,帮助你了解这个平台。 基于Xcode4开发第一个iPhone程序:“Hello World” 由宝玉出品的非常详尽的iOS开发入门教程。
782 0
09.阿里云服务器(Ubantu系统)配置ndk 编译ffmpeg
(创建于2018/1/4) ffmpeg完整的编译过程 1.ls 显示所有目录文件 2.mkdir root 创建文件夹root //将Android文件夹下的所有强制删除 rm -rf android 3.
891 0
C#对接----韵达开发平台--取电子面单
引子 最近根据业务的一些需求,所以放弃从快递鸟对接去电子面单,转而直接对接韵达开发平台:http://open.yundasys.com/ ,中间踩了一些坑,借此做了一个小案例给大伙,瞅瞅,若有需改进之处,还请指出!!! 废话不多数:首先咱先对韵达的一些接口参数了解清楚: 当然附上地址:http://open.
2597 0
SNMP从入门到开发:进阶篇
管理信息库:MIB 我们要扩展mib首先必须清楚mib是如何定义的,用的什么语言,有哪些约定,遵循哪些规则等等。这些基本东西掌握过后,我们就可以很轻松的来写自己的mib文件了。 所谓管理信息库,或者MIB,就是所有代理进程包含的、并且能够被管理进程进行查询和设置的信息的集合,或者叫管理对象的集合,在RFC 1213 [McColghrie 和Rose 1991]中定义了MIB-II,即第二版的MIB库。
947 0
mysql 系统用户最大文件打开数限制
mysql 系统用户最大文件打开数限制 纸上得来终觉浅,绝知此事多宕机...记录一下自己很蠢的一次故障处理过程。   上周的时候,一个刚上线的系统又开始反映登不上了,因为最近这个系统也老是出现这个问题,开发也一直在找问题中,所以也没太在意。
978 0
MFC DDE开发中令人迷惑的问题?
在用MFC(ddeml)开发DDE中,遇到一个令人迷惑的问题, ddeml提供的一些命令,在时钟函数里或按钮事件里运行正常,可是在线程里运行就出现如下错误: "A parameter failed to be validated by the DDEML.
530 0
+关注
异步社区
异步社区(www.epubit.com)是人民邮电出版社旗下IT专业图书旗舰社区,也是国内领先的IT专业图书社区,致力于优质学习内容的出版和分享,实现了纸书电子书的同步上架,于2015年8月上线运营。公众号【异步图书】,每日赠送异步新书。
12049
文章
0
问答
文章排行榜
最热
最新
相关电子书
更多
《2021云上架构与运维峰会演讲合集》
立即下载
《零基础CSS入门教程》
立即下载
《零基础HTML入门教程》
立即下载