xcode4.2实现分段表视图tableview

xcode4.2实现分段表视图tableview
//
//   TableViewMasterViewContr oller.m
//   TableView
//
//   Created by 红雷软件 on 12-5-15.
//   Copyright (c) 2012年 www.soft.com. All rights reserved.
//

#import "TableViewMasterViewContr oller.h"

#import "TableViewDetailViewContr oller.h"

@implementation TableViewMasterViewContr oller

@synthesize detailViewController = _detailViewController;
@synthesize movieTitles;
@synthesize years;

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
      self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
      if (self) {
          self.title = NSLocalizedString(@"Master", @"Master");
      }
      return self;
}

- (void)didReceiveMemoryWarning
{
      [super didReceiveMemoryWarning];
      // Release any cached data, images, etc that aren't in use.
}

#pragma mark - View lifecycle

- (void)viewDidLoad
{
// Do any additional setup after loading the view, typically from a nib.
      //plist file path name
      NSString *path = [[NSBundle mainBundle] pathForResource:@"Movies" ofType:@"plist"];
      NSLog(@"path=%@", path);
      //Dic load plist
      NSDictionary *dic = [[NSMutableDictionary alloc] initWithContentsOfFile:path];
      NSLog(@"dic count=%d", [dic count]);
      NSLog(@"dic:%@", dic);
      self.movieTitles = dic;
      NSArray *array = [self.movieTitles allKeys];
      NSLog(@"array count=%d", [array count]);
      NSLog(@"array:%@", array);
      self.years = array;
      [super viewDidLoad];
}

- (void)viewDidUnload
{
      [super viewDidUnload];
      // Release any retained subviews of the main view.
      // e.g. self.myOutlet = nil;
}

- (void)viewWillAppear:(BOOL)animated
{
      [super viewWillAppear:animated];
}

- (void)viewDidAppear:(BOOL)animated
{
      [super viewDidAppear:animated];
}

- (void)viewWillDisappear:(BOOL)animated
{
[super viewWillDisappear:animated];
}

- (void)viewDidDisappear:(BOOL)animated
{
[super viewDidDisappear:animated];
}

- (BOOL)shouldAutorotateToInterf aceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
      // Return YES for supported orientations
      return (interfaceOrientation != UIInterfaceOrientationPo rtraitUpsideDown);
}

// Customize the number of sections in the table view.
- (NSInteger)numberOfSectionsInTableV iew:(UITableView *)tableView
{
      //return 1;
      return [self.years count];
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
      //return 1;
      NSString *year = [self.years objectAtIndex:section];
      NSArray *movieSection = [self.movieTitles objectForKey:year];
      return [movieSection count];
}

// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
      static NSString *CellIdentifier = @"Cell";
     
      UITableViewCell *cell = [tableView dequeueReusableCellWithI dentifier:CellIdentifier];
      if (cell == nil) {
          cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefa ult reuseIdentifier:CellIdentifier];
          cell.accessoryType = UITableViewCellAccessory DisclosureIndicator;
      }

      // Configure the cell.
      NSString *year = [self.years objectAtIndex:[indexPath section]];
      NSLog(@"year=%@", year);
      NSArray *movieSection = [self.movieTitles objectForKey:year];
      NSLog(@"movieSection=%@", movieSection);
      cell.textLabel.text = [movieSection objectAtIndex:[indexPath row]];
      return cell;
}


- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
{
      NSString *year = [self.years objectAtIndex:section];
      return year;
}




- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
      if (!self.detailViewController) {
          self.detailViewController = [[TableViewDetailViewContr oller alloc] initWithNibName:@"TableViewDetailViewContr oller" bundle:nil];
      }
      [self.navigationController pushViewController:self.detailViewController animated:YES];
}

@end
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值