创建表单

表格视图
1.添加视图View,连接数据源和委托。
控制器头文件
#import <UIKit/UIKit.h>
@interface Simple_TableViewController:UIViewController<UITableViewDdlegate,UITableViewDataSource>
{
  NSArry *listData;
}
@property(nonatomic,retain)NSArry *listData;
@end

Simple_TableViewController.m文件
#import "Simple_TableViewController.h"
@implementation Simple_TableViewController
@synthesize listData;


//创建一个要传递给表的数据的数组
-(void)viewDidLoad
{
 NSArry *arry=[[NSArry alloc] initWithObjects:@"Sleepy",@"Sneezy",@"Bashful",@"Happy",@"Doc",@"Grumpy",@"Dopey",@"Thorin",@"Dorin",@"Nori",@"Ori",@"Balin",@"Dwalin",@"Fili",@"Kili",@"Oin",@"Floin",@"Bifur",@"Bofur",@"Bombur",nil];
self.listData=arry;
[arry release];
[super viewDidLoad];
}
#pragma mark table view Data Source Methods
//返回组成列表的表分区中的行数
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
 return [self.listData count];
}
//绘制表视图其中一行
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
//NSIndexPath对象可获得一行或一个分区,调用方法
//以下是绘制表单
{
//绘制一个单元
 static NSString *SimpleTableIdentifier=@"SimpleTableIdentifier";
 UITableViewCell *cel=[tableView dequeueReusableCelWithIdentifier:SimpleTableIdentifier];
//绘制所有表单单元
 if(cell==nil)
 {
  cell=[[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:SimpleTableIdentifier] autorelease];
 }
//indexPath变量获取要显示哪些行信息
 NSUInteger row=[indexPath row];
//text显示信息
 cell.text=[listData objectAtIndex:row];
//添加图像
UIImage *image=[UIImage imageNamed:@"star.png"];
cell.image=image;
return cell;
}
/*利用委托delegate    处理行是否被选择
-(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 *message=[[NSString alloc] initWithFormat:@"You selected %@",rowValue];
 UIAertView *alert=[[UIAertView alloc] initWithTitle:@"Row Selected!"
message:message
delegate:nil
cancelButtonTitle:@"Yes I Did"
otherButtonTitles:nil];
[alert show];
[message release];
[alert release];
}
*/
@end

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值