创建 UITableViewCell 的方式主要有四种,使用系统自带的 cell 样式,自定义的继承 UITableViewCell 的方式 , xib 创建 cell 和 sb 中创建 cell。
简单的代码添加
//直接在UITableViewCell的生成方法中实现,代码如下
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *identifier = @"cell";
    UITableViewCell  *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
    if (cell == nil) {
        cell = [[UITableViewCell  alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];
        UILabel *label1 = [[UILabel alloc] initWithFrame:CGRectMake(190, 0, 130, cell.frame.size.height)];
        label1.tag = 1;
        [cell.contentView addSubview:label1];
    }
    UILabel *label3 = (UILabel *)[cell.contentView viewWithTag:1];
    label3.text = @"44444";
    return cell;
}
自定义的继承UITableViewCell的类
.h
   @interface Cell3 : UITableViewCell {
       UILabel *_label1;
       UILabel *_label2;
   }
   - (void)setLabel1Text:(NSString *)text1
              label2Text:(NSString *)text2;
   @end
.m
   @implementation Cell3
   - (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
   {
       self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
       if (self) {
           _label1 = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 160, self.frame.size.height)];
           [self.contentView addSubview:_label1];
           _label2 = [[UILabel alloc] initWithFrame:CGRectMake(160, 0, 160, self.frame.size.height)];
           [self.contentView addSubview:_label2];
       }
       return self;
   }
   - (void)setLabel1Text:(NSString *)text1 label2Text:(NSString *)text2
   {
       _label1.text = text1;
       _label2.text = text2;
   }
控制器中的写法
   - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
   {
       static NSString *identifier = @"cell";
       Cell3 *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
       if (cell == nil) {
           cell = [[Cell3 alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];
       }
       [cell setLabel1Text:@"2222" label2Text:@"3333"];
       return cell;
   }
xib 创建 cell
1.先在 xib 中设置 Identifier 设置
2.声明 [self.tableView registerNib:[UINib nibWithNibName:@”Cell2” bundle:[NSBundle mainBundle]] forCellReuseIdentifier:@”Cell2”];
3.在控制器的 UITableView 代理中
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
      Cell2 *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell2"];
      cell.numLabe.text = @"123";
      return cell;
   }