转自:

    http://blog.csdn.net/jinliang_890905/article/details/6408901


1.新建TableViewCell类,继承父类为UITableViewCell

 

1.1 "TableCell.h"

#import <UIKit/UIKit.h>

 

/**

 * 房间桌子显示结构

 * /

@interface TableCell : UITableViewCell {

    UILabel *tableNoLable; // 桌子号

    UIImageView *tableImageView; // 桌子图片

     UIImageView *tableStateImageView; // 桌子状态图片

@property (nonatomic ,retain) IBOutlet UILabel *tableNoLable;// 桌子号

@property (nonatomic ,retain) IBOutlet UIImageView *tableImageView;// 桌子图片

@property (nonatomic ,retain) IBOutlet UIImageView *tableStateImageView;// 桌子状态图片

1.2 TableCell. 

#import "TableCell.h"

@implementation TableCell

@synthesize tableNoLable; // 桌子号

@synthesize tableImageView; // 桌子图片

@synthesize tableStateImageView; // 桌子状态图片

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {

    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {

        // Initialization code

    }

    return self;

}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {

    [super setSelected:selected animated:animated];

    // Configure the view for the selected state

}

- (void)dealloc {

 [tableNoLable release];

 [tableImageView release];

 [hand3ImageView release];

    [super dealloc];

}

@end

 

 

 

1.3 布置布局文件( xib 文件)指明 class 为自己定义的 tabelcellview

new 一个Empty Xib文件,其中不包含view, 在libriary中拖一个UITableCell到两个图标的框中,双击cellview,指明class为cell.m文件,开始编辑

 

 

2. 页面中在 tableView 中加载自己的 cell

 

#import "TableCell.h"

// 设置房间桌子数

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{

  [Util showLog:@"numberOfRowsInSection"];

  return g_Room.wTableCount;

}

// 设置单元格的高度

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{

  [Util showLog:@"heightForRowAtIndexPath"];

  return kTableViewRowHeight;

}

// 设置单元个样式

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

  [Util showLog:@"cellForRowAtIndexPath start"];

 

  static NSString *tableCellIdentifier = @"TableCellIdentifier";

  TableCell *cell = (TableCell *)[tableView dequeueReusableCellWithIdentifier:tableCellIdentifier];

  [Util showLog:@"TableCellIdentifier"];

  if(cell == nil){

  NSArray *nib = [[NSBundle mainBundle]loadNibNamed:@"TableCell" owner:self options:nil];

  for(id oneObject in nib){

   if([oneObject isKindOfClass:[TableCell class]]){

    cell = (TableCell *)oneObject;

//***** 自己设计每个 cell 的内容,此函数会回调 table 的行数次,行数为 numberOfRowsInSection:(NSInteger)section 函数指定

  // 显示桌子号码

  NSUInteger row = [indexPath row] + 1;

  NSString *str =[NSString stringWithFormat:@"%d",row];

  cell.tableNoLable.text = [[@"  " stringByAppendingString:str] stringByAppendingString:@"  "];

  [Util showLog:@"tableNoLable"];

 

  if(deskshowFlg){

  // 获取要绘画的桌子信息

  Desk *tempDesk = [g_DeskArray objectAtIndex:[indexPath row]];

   }

  }

  }