Iphone表实例应用
来源:互联网 发布:恒大海上威尼斯 知乎 编辑:程序博客网 时间:2024/05/04 11:08
//
// Simple_TableViewController.m
// Simple Table
//
// Created by sinnMac05 on 3/30/10.
// Copyright sinn 2010. All rights reserved.
//
#import "Simple_TableViewController.h"
@implementation Simple_TableViewController
@synthesize listData;
@synthesize images;
/*
// The designated initializer. Override to perform setup that is required before the view is loaded.
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
if (self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]) {
// Custom initialization
}
return self;
}
*/
/*
// Implement loadView to create a view hierarchy programmatically, without using a nib.
- (void)loadView {
}
*/
/*
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
[super viewDidLoad];
}
*/
/*
// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// 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 {
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
- (void)dealloc {
[super dealloc];
}
-(void)viewDidLoad{
NSArray *imageNames=[[NSArray alloc] initWithObjects:@"u=1055417007,3623440744&fm=0&gp=0.jpg",
@"u=1023570728,1484262426&fm=0&gp=0.jpg",
@"u=1477798512,22194711&fm=0&gp=0.jpg",
@"u=3788263137,3792757984&fm=0&gp=0.jpg",nil];
NSArray *array=[[NSArray alloc] initWithObjects:@"王秋磊 13012345678",@"赵齐奎 13111111111",@"倪雨成 15888888888",@"王建刚 13855555555",nil];
//向表视图传递一个数组
self.listData=array;
self.images=imageNames;
//self.images=newImages;
[imageNames release];
[array release];
[super viewDidLoad];
}
/*
tableview方法的作用是在当前视图中显示多少行
tableView 表视图,section表示第几个分区
*/
-(NSInteger)tableView:(UITableView*) tableView numberOfRowsInSection:(NSInteger)section{
//分区中的行数是数组中数组项的数目。
return [self.listData count];
}
/*
下面的方法是获得一行,
tableView 是对所请求的表的引用,
NSIndexPath类可以将分区和行绑定到一个对象中,如果xiang
*/
-(UITableViewCell*) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *) indexPath
{
//充当表示某种表单元的键,在此表中只创建了一个单元,因此只定义一种标识符。
static NSString *simpleTableIdentifier=@"SimpleTable";
//根据simpleTableIdentifier标识符初始化,UITableViewCell,dequeueReusableWithIdentifier返回一个
//可重复使用的表视图单元,改单元格位于标识赋simpleTableIdentifier下
UITableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:
simpleTableIdentifier];
//判断可重复使用的表单元是否为空,
if(cell==nil){
cell=[[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:
simpleTableIdentifier]autorelease];
}
//通过NSIndexPath知道表视图需要显示第几行
NSInteger row=[indexPath row];
//获得所显示行的数据,而后将数据给cell.textLable
cell.textLabel.text=[listData objectAtIndex:row];
/*
得到图片并显示在当前行
*/
UIImage *image=[UIImage imageNamed:[images objectAtIndex:row]];
cell.imageView.image=image;
[image release];
return cell;
}
/*
获得当前所选择的行,如果第一行被选中,其索引始终为零,那么他将返回nil,表示实际上没有行被选中。
*/
-(NSIndexPath *)tableView:(UITableView *)tableView willSelectRowAtIndexPath:(NSIndexPath *)indexPath{
NSUInteger row=[indexPath row];
if(row==0)
return nil;
return indexPath;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
//得到当前所选择的行
NSUInteger row=[indexPath row];
//通过行,得到数据
NSString *rowValue=[listData objectAtIndex:row];
NSString *messages=[[NSString alloc] initWithFormat:@"用户: %@/n",rowValue];
//设置警告对话框
UIAlertView *alert=[[UIAlertView alloc] initWithTitle:messages message:@"Row selected" delegate:nil cancelButtonTitle:@"Yes I Did" otherButtonTitles:nil];
[alert show];
[messages release];
[alert release];
}
@end
- Iphone表实例应用
- iPhone企业应用实例分析之二:程序处理流程
- iPhone企业应用实例分析之三:程序框架分析
- iPhone应用开发之自动登陆实例操作
- 外部表应用实例
- 顺序表应用实例
- hash表实例应用
- iphone实例Hello word
- iphone模型数据 实例
- iphone推送消息 实例
- iphone实例集锦
- iphone实例集锦
- iphone 开发实例代码
- iPhone企业应用实例分析之一:系统介绍和需求及主要用例
- iPhone企业应用实例分析之四:技术要点分析(1)
- 圆角矩形、阴影、伪元素的应用实例iphone手机壳
- 创建表的应用实例
- 顺序表的应用实例
- 键盘画图
- 名词解释:SOA
- 利用xp_cmdshell来ping某台PC是否连通
- c++中new之出错
- 使标题栏的关闭按钮无效
- Iphone表实例应用
- IIS中ASP.net调试出现进程被打断的调整
- WEBLOGIC的安装、配置和启动
- wamp配置
- 振动充电-Humdinger公司的微型风力发电器
- 硬件常见问题
- JSF 2 简介
- 区分JS中的null,undefined,“”,0和false
- About linkedserver