UITableViewCell的使用——自定义tableView视图
视图需要我们自己去定义样式时用到了TableViewCell组件,效果如下
首先创建View Based App工程,在.xib文件中拖入一个Table View,前面我们说到了,这里就不再重复,注意连接协议和两个必须方法的实现。完成.h中代码
若不需要cell则改为:
static NSString *CellIdentifier2 = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier2];
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier2] autorelease];
cell.textLabel.text =@"CCCCCCCC";
[cell.textLabel setFont:[UIFont fontWithName:@"Helvetica" size:16.0f]];
//cell.accessoryView=[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"sign_10x12.png"]];
cell.selectionStyle = UITableViewCellSelectionStyleBlue;
[cell.textLabel setTextColor:[UIColor colorWithRed:0/255.0 green:106/255.0 blue:166/255.0 alpha:1.0]];
return cell;
下面我们新建一个类,注意subclass选择UITableViewCell,名称为MyCell,生成之后再创建相应的xib文件
双击MyCell.xib,将Table View Cell拖入主窗口中,并且删除原主窗口中的View图标
在.h文件中完成代码![]()