#import "ListringCell.h"
@implementation ListringCell
@synthesize _name,_time,_touxiang,_title;
-(void)dealloc{
self._name=nil;
self._time=nil;
self._title=nil;
self._touxiang=nil;
[super dealloc];
}
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self) {
// Initialization code
//创建三个lable和一个imageview 并添加到cell
UIColor * col=[UIColor scrollViewTexturedBackgroundColor];
_name=[[UILabel alloc]initWithFrame:CGRectMake(0, 50, 50, 20)];
_time=[[UILabel alloc]initWithFrame:CGRectMake(50, 50, 270, 20)];
_title=[[UILabel alloc]initWithFrame:CGRectMake(50, 0, 270, 50)];
_touxiang=[[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 50, 50)];
_touxiang.frame=CGRectMake(0, 0, 50, 50);
_time.backgroundColor=col;
_name.backgroundColor=col;
_title.backgroundColor=col;
//name字体自适应大小 以及居中显示
_name.adjustsFontSizeToFitWidth = YES;
_name.textAlignment = NSTextAlignmentCenter;
_title.textAlignment = NSTextAlignmentCenter;
_time.textAlignment = NSTextAlignmentCenter;
[self addSubview:_name];
[self addSubview:_time];
[self addSubview:_touxiang];
[self addSubview:_title];
[_title release];
[_touxiang release];
[_name release];
[_time release];
}
return self;
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
[super setSelected:selected animated:animated];
// Configure the view for the selected state
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
//用自己的自定义cell类创建cell
ListringCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell==nil) {
cell =[[[ListringCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier]autorelease];
}
// Configure the cell...
//这里让自定义cell的lable和imageview放入自己需要放的东西
[cell _name ].text=(NSString *)[[tableData objectAtIndex:[indexPath row]]objectForKey:@"nickname"];
[cell _time ].text=(NSString *)[[tableData objectAtIndex:[indexPath row]]objectForKey:@"time"];
[cell _title ].text=(NSString *)[[tableData objectAtIndex:[indexPath row]]objectForKey:@"title"];
cell._touxiang.image=[UIImage imageNamed:[[tableData objectAtIndex:[indexPath row]] objectForKey:@"touxiang"]];
return cell;
}