您的位置:首页 > 产品设计 > UI/UE

如何用.xib 自定义UITableViewCell

2013-04-11 11:50 274 查看
1、新建一个file,让其继承UITableViewCell,自己定义名字。如:MyTableViewCell

l


2、新建一个.xib文件,自己定义名字。如:MyTableViewCell.xib



3、以上两步完成后就可以往.xib托控件了。 首先托一个UITableViewCell,然后托自己需要的控件到这个cell上面,如下图:



注意:右上角,这里一定要填写在第1步新建File时的那个.h文件的名字“MyTableViewCell”。如图:






4、完成以上三步时,最后在

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath
*)indexPath

{

static
NSString* cellIdentifier =@"Cell";
//向当前的tableView中注册cell信息,才能在cell子类控件上添加需要显示的数据
UINib*
nib = [UINib nibWithNibName:@"MyTableViewCell"bundle:nil];
[tableViewregisterNib:nib
forCellReuseIdentifier:cellIdentifier];

GameAndSoftwareTableCell* cell = (GameAndSoftwareTableCell*)[tableViewdequeueReusableCellWithIdentifier:cellIdentifier];
if (cell ==
nil) {

cell = [[[GameAndSoftwareTableCellalloc]
initWithStyle:UITableViewCellStyleDefaultreuseIdentifier:cellIdentifier]
autorelease];
}

cell.titleLabel.text =@"Adobe Photoshop Elements 11 Editor";

cell.contentLabel.text =@"Works great with iPhoto when you are ready to go
beyond the basics. Live in the monent knowing that Adobe@ PhotoShop Elements 11 softWare makes it easy to turn your .....";
return cell;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: