创建表单-定制视图单元


1.定制表单元-添加子视图
定义一个CellsViewController子视图
#import "CellsViewController"
@implementation CellsViewController
@synthesize computers;
-(void)viewDidload{
NSDictionary *row1=[[NSDictonary alloc]initWithObjectsAndKeys:@"MacBook",@"Name",@"white",@"color",nil];
NSDictionary *row2=[[NSDictonary alloc]initWithObjectsAndKeys:@"MacBook2",@"Name",@"white",@"color",nil];
NSDictionary *row3=[[NSDictonary alloc]initWithObjectsAndKeys:@"MacBook3",@"Name",@"white",@"color",nil];
NSArray *array=[[NSArray alloc]initWithObjects:row1,row2,row3,nil];
self.computers=array;
[row1 release];
[row2 release];
[row3 release];
[array release];
}

#pragma mark table Data source methods
-(NSInteger)tableView:(UItableView *)tableView numberOfRowsInSecton:(NSiteger)section
{return [self.computers count];}
//自定义单元格 拥有两行的
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{ static NSString *CelltableIdentifier=@"CellTableIdentifier";
UITableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:CellTableIdentifier];
if(cell==nil){
CGRect cellFrame=CGRectMake(0,0,300,65);
cell=[[[UITableViewCell alloc]initWithFrame:cellFrame reseIdentifier:CellTableIdentifier]autorelease];

CGRect nameLableRect=CGRectMake(0,5,70,15);
UILabel *nameLabel=[[UILabel alloc]initWithFrame:nameLableRec];
nameLabel.textAlignment=UITextAlignmentright;
nameLabel.text=@"name";
nameLabel.font={UIFont boldSystemFontOfSize:12};
[cell.contentView addSubview:nameLabel];
[nameLabel release];

CGRect nameValueRect=CGRectMake(80,5,200,15);
UILabel *nameValue=[[UILabel alloc]initWithFrame:nameValueRect];
nameValue.tag=knameValuetag;
[cell.contentVie addSubview:nameValue];
[nameValue release];
//同理在创建一行COLOR
........
}
NSUInteger row=[indexPath row];
NSDictionary *rowData=[self.computers objectAtIndex:row];
UILabel *name=(UILabel *)[cell.contentView viewWithTag:kNameValuetag];
name.text=[rowData objectForKey:@"Name"];
UILabel *color=(UILabel *)[cell.contentView viewWithTag:kColorValuetag;
color.text=[rowData objectForKey:@"Color"];
return cell;
}

2.使用UITableViewCell的自定义子类
在子类的nib中添加UITableViewCell的子类到View中,构建需要的格式
添加方法:
-(id)initWithFram:(CGRect)frame reuseIdentifier:(NSString *)reuseIdentifier
{if(self=[super initWithFrame:frame reuseIdentifier:reuseIdentifier])}


-(void)setSelected:(BOOL)selected animatied:(BOOL)animated
{[super setSelected:selected animated: ainmated];}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值