2. 增加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"
@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{
NSString * string=[listData objectAtIndex:[indexPath row]];
UIAlertView *alert=[[UIAlertView alloc] initWithTitle:@"提示" message:string delegate:self cancelButtonTitle:@"確定" otherButtonTitles: nil];
[alert show];
}
@end
3.執行結果
沒有留言:
張貼留言