1. 參考前一篇TableView教學說明 http://cheng-min-i-taiwan.blogspot.tw/2012/11/ios-tableview_3.html 以及 畫面切換說明。http://cheng-min-i-taiwan.blogspot.tw/2012/10/ios.html
2. 選擇File->New 建立第二個畫面程式。
(按下Create鈕)
3.增加TableView被選擇後的程式(DLIViewController.m 中藍色字)
//
// DLIViewController.m
// tableView
//
// Created by Lin Cheng-Min on 12/11/3.
// Copyright (c) 2012年 Lin Cheng-Min. All rights reserved.
//
#import "DLIViewController.h"
#import "DLIViewController2.h"
@interface DLIViewController ()
@end
@implementation DLIViewController
@synthesize listData;
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
listData = [[NSArray alloc] initWithObjects:@"a",@"b",@"c", nil];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
return [listData count];
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
static NSString *tableIdentifier = @"Simple table";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:tableIdentifier];
if(cell == nil){
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:tableIdentifier];
}
cell.textLabel.text = [listData objectAtIndex:indexPath.row];
UIImage *cellImage = [UIImage imageNamed:@"nkut_logo.jpg"];
cell.imageView.image = cellImage;
return cell;
}
-(void)tableView:(UITableView *)tableView didEndDisplayingCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath{
cell.textLabel.text = [listData objectAtIndex:[indexPath row]];
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
DLIViewController2 *controller = [[DLIViewController2 alloc] initWithNibName:nil bundle:nil];
[self presentViewController:controller animated:YES completion:NULL];
}
@end
4. 執竹結果
(畫面切換)
沒有留言:
張貼留言