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
    评论
Xcode 中实现视图之间转换的方法有以下几种: 1. 使用 Navigation Controller Navigation Controller 是 Xcode 中用于管理多个视图控制器的容器控制器。它可以实现视图之间的转换,并提供了向前和向后的导航功能。在使用 Navigation Controller 时,需要先将起始视图控制器嵌入到 Navigation Controller 中,然后在需要转换到其他视图时,使用 push 或者 present 方法实现转换。使用 Navigation Controller 的好处是可以轻松地实现导航栏和工具栏的添加,提高了应用程序的用户体验。 2. 使用 Tab Bar Controller Tab Bar Controller 也是 Xcode 中的一个容器控制器,它可以管理多个视图控制器,将它们放置在一个 Tab Bar 中,用户可以通过点击 Tab Bar 上的不同标签来切换视图。使用 Tab Bar Controller 可以轻松地实现应用程序的主界面,同时也可以实现视图之间的切换。 3. 使用 Segue Segue 是 Xcode 中用于视图之间转换的标准方式。在 Interface Builder 中,可以通过拖拽来创建 segue,然后在需要进行视图转换的时候,调用 performSegueWithIdentifier 方法。在使用 Segue 时,需要在两个视图控制器之间建立一个连接,同时需要为 Segue 设置一个标识符,以便在代码中调用。Segue 提供了多种转换方式,包括 push、modal、popover 等,可以根据需要选择不同的方式。 4. 使用代码进行转换 除了使用容器控制器和 Segue 之外,还可以使用代码进行视图之间的转换。在代码中,可以使用 present、dismiss、push、pop 等方法来进行转换。这种方式适用于需要动态创建视图控制器或者需要在转换时进行一些额外的处理的情况。 以上是在 Xcode 中实现视图之间转换的一些常用方法,可以根据具体情况选择不同的方式。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值